Add support for PEAK PCMCIA PCAN-PC card
Hi,
Please find below a new patch which goal is to include the support of the PEAK-System PCMCIA board PCAN-PC Card. This board is SJA1000 based and is available as a single or dual CAN channel version.
drivers/net/can/sja1000/Kconfig +7 -0
@@ -43,6 +43,13 @@ config CAN_EMS_PCI CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). +config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card" + depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCI
drivers/net/can/sja1000/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o obj-$(CONFIG_CAN_TSCAN1) += tscan1.o
drivers/net/can/sja1000/peak_pcmcia.c new file +707 -0
707 lines not on this page · raw message
Marc Kleine-Budde
maintainerHello,
Quoted 3 lines · Stephane Grosjean
Please find below a new patch which goal is to include the support of the PEAK-System PCMCIA board PCAN-PC Card. This board is SJA1000 based and is available as a single or dual CAN channel version.
The driver looks good, I cannot comment on the PCMCIA stuff though., see comments inline.
Pleae use git send-mail to send your patches, please don't forget the S-o-b line in the patch description.
Quoted 45 lines
drivers/net/can/sja1000/Kconfig +7
-0@@ -43,6 +43,13 @@ config CAN_EMS_PCI CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). +config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card" + depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCIdrivers/net/can/sja1000/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o obj-$(CONFIG_CAN_TSCAN1) += tscan1.odrivers/net/can/sja1000/peak_pcmcia.c new file +9
-0@@ -0,0 +1,707 @@ +/* +* CAN driver for PEAK-System PCAN-PCARD +* Derived from the PCAN project file driver/src/pcan_pccard.c +* +* Copyright (C) 2006-2009 PEAK System-Technik GmbH +* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the version 2 of the GNU General Public License
drivers/net/can/sja1000/peak_pcmcia.c line 19
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+* as published by the Free Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Please remove the address. The FSF sometimes relocates it's office.
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/netdevice.h> +#include <linux/delay.h> +#include <linux/timer.h>
drivers/net/can/sja1000/peak_pcmcia.c line 36
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+#include <linux/io.h> +#include <pcmcia/cistpl.h> +#include <pcmcia/ds.h> +#include <linux/can.h> +#include <linux/can/dev.h> +#include <linux/stringify.h> +#include "sja1000.h" + +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"
Can you use the same name for the driver and the .c file?
drivers/net/can/sja1000/peak_pcmcia.c line 45
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+ +/* PEAK-System PCMCIA driver version */ +#define DRV_VERSION_MAJOR 0 +#define DRV_VERSION_MINOR 2 +#define DRV_VERSION_SUBMINOR 0 + +#define DRV_VERSION_STRING __stringify(DRV_VERSION_MAJOR)"."\ + __stringify(DRV_VERSION_MINOR)"."\ + __stringify(DRV_VERSION_SUBMINOR)
please add whitespace before "\"
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+ +MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_DESCRIPTION ("CAN driver for PEAK-System PCAN-PC Cards" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_SUPPORTED_DEVICE ("PEAK PCAN-PC Card" ); +MODULE_VERSION (DRV_VERSION_STRING );
drivers/net/can/sja1000/peak_pcmcia.c line 61
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2) + +#define DRV_MANF_ID 0x0377 +#define DRV_CARD_ID 0x0001 + +#define DRV_CHAN_SIZE 0x20 +#define DRV_CHAN_OFF (c) ((c)*DRV_CHAN_SIZE)
please add whitespace before and after "*"
Quoted 59 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +59
-0+#define DRV_COMN_OFF (DRV_CHAN_OFF(DRV_CHAN_MAX)) +#define DRV_COMN_SIZE 0x40 + +/* common area registers */ +#define DRV_CCR 0x00 +#define DRV_CSR 0x02 +#define DRV_CPR 0x04 +#define DRV_SPI_DIR 0x06 +#define DRV_SPI_DOR 0x08 +#define DRV_SPI_ADR 0x0a +#define DRV_SPI_INR 0x0c +#define DRV_FW_MAJOR 0x10 +#define DRV_FW_MINOR 0x12 + +/* CCR bits */ +#define DRV_CCR_CLK_16 0x00 +#define DRV_CCR_CLK_10 0x01 +#define DRV_CCR_CLK_21 0x02 +#define DRV_CCR_CLK_8 0x03 +#define DRV_CCR_CLK_MASK DRV_CCR_CLK_8 + +#define DRV_CCR_RST_CHAN (c) (0x01 << ((c) + 2)) +#define DRV_CCR_RST_ALL (DRV_CCR_RST_CHAN(0) | DRV_CCR_RST_CHAN(1)) +#define DRV_CCR_RST_MASK DRV_CCR_RST_ALL + +/* led selection bits */ +#define DRV_LED (c) (1 << (c)) +#define DRV_LED_ALL (DRV_LED(0) | DRV_LED(1)) + +/* led state value */ +#define DRV_LED_ON 0x00 +#define DRV_LED_FAST 0x01 +#define DRV_LED_SLOW 0x02 +#define DRV_LED_OFF 0x03 + +#define DRV_CCR_LED_CHAN (s, c) ((s) << (((c) + 2) << 1)) + +#define DRV_CCR_LED_ON_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_ON, c) +#define DRV_CCR_LED_FAST_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_FAST, c) +#define DRV_CCR_LED_SLOW_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_SLOW, c) +#define DRV_CCR_LED_OFF_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_OFF, c) +#define DRV_CCR_LED_MASK_CHAN (c) DRV_CCR_LED_OFF_CHAN(c) +#define DRV_CCR_LED_OFF_ALL (DRV_CCR_LED_OFF_CHAN(0) | \ + DRV_CCR_LED_OFF_CHAN(1)) +#define DRV_CCR_LED_MASK DRV_CCR_LED_OFF_ALL + +#define DRV_CCR_INIT (DRV_CCR_CLK_16 | DRV_CCR_RST_ALL | DRV_CCR_LED_OFF_ALL) + +#define DRV_CSR_SPI_BUSY 0x04 +#define DRV_SPI_MAX_WAIT_LOOP 100 +#define DRV_WRITE_MAX_LOOP 1000 + +/* +* The board configuration is probably following: +* RX1 is connected to ground. +* TX1 is not connected. +* CLKO is not connected. +* Setting the OCR register to 0xDA is a good idea. +* This means normal output mode, push-pull and the correct polarity.
drivers/net/can/sja1000/peak_pcmcia.c line 130
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+*/ +#define DRV_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL) + +/* +* In the CDR register, you should set CBP to 1. +* You will probably also want to set the clock divider value to 7 +* (meaning direct oscillator output) because the second SJA1000 chip +* is driven by the first one CLKOUT output. +*/ +#define DRV_CDR (CDR_CBP | CDR_CLKOUT_MASK)
Can you please properly align all the defines above (or don't align at all). I personally prefer a common prefix for all functions and defines used in a driver, maybe use PCAN_ instead of DRV_
Quoted 45 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +45
-0+ +struct pcan_channel { +struct net_device *netdev; +unsigned long prev_rx_bytes; +unsigned long prev_tx_bytes; +}; + +/* PCAN-PC Card private structure */ +struct pcan_pccard { +struct pcmcia_device *dev; +int chan_count; +struct pcan_channel channel[DRV_CHAN_MAX ]; +u8 ccr; +void __iomem *ioport_addr; +struct timer_list led_timer; +}; + +static struct pcmcia_device_id pcan_table[] = { +PCMCIA_DEVICE_MANF_CARD (DRV_MANF_ID ,DRV_CARD_ID ), +PCMCIA_DEVICE_NULL , +}; + +MODULE_DEVICE_TABLE (pcmcia, pcan_table); + +static void pcan_set_leds (struct pcan_pccard *card,u8 mask,u8 state); + +/* +* start timer which controls leds state +*/ +static void pcan_start_led_timer (struct pcan_pccard *card) +{ +if (!timer_pending (&card->led_timer)) +mod_timer (&card->led_timer, jiffies +HZ ); +} + +/* +* stop the timer which controls leds state +*/ +static void pcan_stop_led_timer (struct pcan_pccard *card) +{ +del_timer_sync (&card->led_timer); +} + +/* +* read a sja1000 register
drivers/net/can/sja1000/peak_pcmcia.c line 185
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+*/ +static u8 pcan_read_canreg (const struct sja1000_priv *priv,int port) +{ +return ioread8 (priv->reg_base + port); +} + +/* +* write a sja1000 register +*/ +static void pcan_write_canreg (const struct sja1000_priv *priv,int port,u8 v)
In the functions below port is always u8, here an int.
drivers/net/can/sja1000/peak_pcmcia.c line 192
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+{ +struct pcan_pccard *card = priv->priv; +int c = (priv->reg_base - card->ioport_addr) /DRV_CHAN_SIZE ; + +/* sja1000 register changes control the leds state */ +switch (port) { +case REG_MOD :
I would use:
if (port == REG_MOD), instead of the outer switch.
drivers/net/can/sja1000/peak_pcmcia.c line 198
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+switch (v) { +case MOD_RM : +/* Reset Mode: set led on */ +pcan_set_leds (card,DRV_LED (c),DRV_LED_ON ); +break ; +case 0x00 :
is there a defefine for 0x0, too?
Quoted 34 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +34
-0+/* Normal Mode: led slow blinking and start led timer */ +pcan_set_leds (card,DRV_LED (c),DRV_LED_SLOW ); +pcan_start_led_timer (card); +break ; + } +break ; + } +iowrite8 (v, priv->reg_base + port); +} + +/* +* read a register from the common area +*/ +static u8 pcan_read_reg (struct pcan_pccard *card,u8 port) +{ +return ioread8 (card->ioport_addr +DRV_COMN_OFF + port); +} + +/* +* write a register into the common area +*/ +static void pcan_write_reg (struct pcan_pccard *card,u8 port,u8 v) +{ +/* cache ccr value */ +if (port ==DRV_CCR ) { +if (card->ccr == v) +return ; + card->ccr = v; + } + +iowrite8 (v, card->ioport_addr +DRV_COMN_OFF + port); +} + +/*
drivers/net/can/sja1000/peak_pcmcia.c line 242
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+* wait for SPI engine while it is busy +*/ +static int pcan_wait_spi_busy (struct pcan_pccard *card) +{ +int i; + +for (i =0 ; i <DRV_SPI_MAX_WAIT_LOOP ; i++) { +if (!(pcan_read_reg (card,DRV_CSR ) &DRV_CSR_SPI_BUSY )) +break ; +schedule ();
How long does it take? Can you use msleep or usleep_range here?
drivers/net/can/sja1000/peak_pcmcia.c line 246
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ } + +if (i >=DRV_SPI_MAX_WAIT_LOOP ) { +dev_err (&card->dev->dev,"failure: spi engine busy\n" );
please use netdev_err()
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+return -EIO ; + } + +return 0 ; +} +
drivers/net/can/sja1000/peak_pcmcia.c line 262
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+/* +* write data in device eeprom +*/ +static int pcan_write_eeprom (struct pcan_pccard *card,u16 addr,u8 v) +{ +u8 status; +int err, i; + +/* write instruction */ +pcan_write_reg (card,DRV_SPI_INR ,0x06 );
Can you define some macros for this and the following constants?
Quoted 14 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +14
-0+ err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; + +/* wait until write enable */ +for (i =0 ; i <DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */ +pcan_write_reg (card,DRV_SPI_INR ,0x05 ); + err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; +/* WEL */ + status =pcan_read_reg (card,DRV_SPI_DIR ); +if (status &0x02 )
drivers/net/can/sja1000/peak_pcmcia.c line 286
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+break ; + } + +if (i >=DRV_WRITE_MAX_LOOP ) { + err = -EIO ; + goto write_eeprom_err; + } + +/* set address and data */ +pcan_write_reg (card,DRV_SPI_ADR , addr &0xff );
The 3rd argument of pcan_write_reg() is u8, so the 0xff is not needed.
Quoted 22 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +22
-0+pcan_write_reg (card,DRV_SPI_DOR , v); + +/* write instruction with bit3 set accoridng to address */ +pcan_write_reg (card,DRV_SPI_INR , ((addr &0x100 ) ?8 :0 ) |0x02 ); + err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; + +/* wait while write in progress */ +for (i =0 ; i <DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */ +pcan_write_reg (card,DRV_SPI_INR ,0x05 ); + err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; + + status =pcan_read_reg (card,DRV_SPI_DIR ); +if (!(status &0x01 )) +break ; + } + +if (i >=DRV_WRITE_MAX_LOOP ) {
drivers/net/can/sja1000/peak_pcmcia.c line 318
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ err = -EIO ; + goto write_eeprom_err; + } + +return 0 ; + +write_eeprom_err: +dev_info (&card->dev->dev, +"writing 0x%x in eeprom @0x%x failed (err %d)\n" , + v, addr, err);
netdev_info()
Quoted 35 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +35
-0+ +return err; +} + +/* +* control the leds +* @led_mask: should be an or made of DRV_LED(x) +* @state: DRV_LED_ON, DRV_LED_OFF, DRV_LED_SLOW or DRV_LED_FAST +*/ +static void pcan_set_leds (struct pcan_pccard *card,u8 led_mask,u8 state) +{ +u8 ccr = card->ccr; +int i; + +for (i =0 ; i < card->chan_count; i++) +if (led_mask &DRV_LED (i)) { +/* clear corresponding led bits in ccr */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); +/* then set new bits */ + ccr |=DRV_CCR_LED_CHAN (state, i); + } + +/* real write only if something has changed in ccr */ +pcan_write_reg (card,DRV_CCR , ccr); +} + +/* +* enable/disable CAN connector power +*/ +static inline void pcan_set_can_power (struct pcan_pccard *card,int onoff) +{ +pcan_write_eeprom (card,0 , (onoff) ?1 :0 ); +} + +/*
drivers/net/can/sja1000/peak_pcmcia.c line 363
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+* set leds state according to channel activity +*/ +static void pcan_led_timer (unsigned long arg) +{ +struct pcan_pccard *card = (struct pcan_pccard *)arg; +struct net_device *netdev; +u8 ccr = card->ccr; +int i, up_count; + +for (i = up_count =0 ; i < card->chan_count; i++) {
Personally I would not initialize up_count in the for() loop, as it is unrelated to it.
Quoted 80 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +80
-0+/* default is: not configured */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_ON_CHAN (i); + + netdev = card->channel[i].netdev; +if (!netdev || !(netdev->flags &IFF_UP )) +continue ; + + up_count++; + +/* no activity (but configured) */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_SLOW_CHAN (i); + +/* if bytes counters changed, set fast blinking led */ +if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) { + card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes; + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_FAST_CHAN (i); + } +if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) { + card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes; + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_FAST_CHAN (i); + } + } + +/* write the new leds state */ +pcan_write_reg (card,DRV_CCR , ccr); + +/* restart timer (except if no more configured channels) */ +if (up_count) +mod_timer (&card->led_timer, jiffies +HZ ); +} + +/* +* interrupt service routine +*/ +static irqreturn_t pcan_isr (int irq,void *dev_id) +{ +struct pcan_pccard *card = dev_id; +struct net_device *netdev; +irqreturn_t retval =IRQ_NONE ; +int i, again; + +do { + again =0 ; + +/* Check interrupt for each channel */ +for (i =0 ; i < card->chan_count; i++) { + netdev = card->channel[i].netdev; +if (!netdev) +continue ; + +if (sja1000_interrupt (irq, netdev) ==IRQ_HANDLED ) + again =1 ; + } + +/* At least one channel handled the interrupt */ +if (again) + retval =IRQ_HANDLED ; + + }while (again); + +return retval; +} + +/* +* free all resources used by the channels and switch off leds and can power +*/ +static void pcan_free_channels (struct pcan_pccard *card) +{ +int i; +u8 led_mask =0 ; + +for (i =0 ; i < card->chan_count; i++) { +struct net_device *netdev; +char name[IFNAMSIZ ]; + + led_mask |=DRV_LED (i);
drivers/net/can/sja1000/peak_pcmcia.c line 453
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ + netdev = card->channel[i].netdev; +if (!netdev) +continue ; + +strncpy (name, netdev->name,IFNAMSIZ ); +unregister_sja1000dev (netdev); +free_sja1000dev (netdev); + +dev_info (&card->dev->dev,"%s removed\n" , name);
netdev_info()...maybe remove altogether
Quoted 22 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +22
-0+ } + +if (pcmcia_dev_present (card->dev)) { +pcan_set_leds (card, led_mask,DRV_LED_OFF ); +pcan_set_can_power (card,0 ); + } + +ioport_unmap (card->ioport_addr); +} + +/* +* check if a CAN controller is present at the specified location +*/ +static inline int pcan_check_channel (struct sja1000_priv *priv) +{ +/* make sure SJA1000 is in reset mode */ +pcan_write_canreg (priv,REG_MOD ,1 ); +pcan_write_canreg (priv,REG_CDR ,CDR_PELICAN ); + +/* read reset-values */ +if (pcan_read_canreg (priv,REG_CDR ) ==CDR_PELICAN ) +return 1 ;
drivers/net/can/sja1000/peak_pcmcia.c line 485
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ +return 0 ; +} + +static int pcan_add_channels (struct pcan_pccard *card) +{ +struct pcmcia_device *dev = card->dev; +int i, err; +u8 ccr =DRV_CCR_INIT ; +unsigned long rst_time;
^^^^^^^^
this var is used write only, please remove.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ +/* init common registers (reset channels and leds off) */ + card->ccr = ~ccr; +pcan_write_reg (card,DRV_CCR , ccr);
drivers/net/can/sja1000/peak_pcmcia.c line 499
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ rst_time = jiffies; + +/* wait 2ms before unresetting channels */ +mdelay (2 ); + + ccr &= ~DRV_CCR_RST_ALL ; +pcan_write_reg (card,DRV_CCR , ccr); + +/* create one network device per channel detected */ +for (i =0 ; i <DRV_CHAN_MAX ; i++) {
For documentation reasons I suggest to use ARRAY_SIZE(card->channel) instead of DRV_CHAN_MAX.
drivers/net/can/sja1000/peak_pcmcia.c line 506
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+struct net_device *netdev; +struct sja1000_priv *priv; + + netdev =alloc_sja1000dev (0 ); +if (!netdev) { + err = -ENOMEM ; +break ;
please do a proper cleanup if this fails with i != 0.
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+ } + +/* update linkages */ + priv =netdev_priv (netdev); + priv->priv = card;
drivers/net/can/sja1000/peak_pcmcia.c line 521
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+SET_NETDEV_DEV (netdev, &dev->dev); + + priv->irq_flags =IRQF_SHARED ; + netdev->irq = dev->irq; + priv->reg_base = card->ioport_addr +DRV_CHAN_OFF (i); + +/* check if channel is present */ +if (!pcan_check_channel (priv)) { +dev_err (&dev->dev,"channel %d not present\n" , i); +free_sja1000dev (netdev);
same here
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+continue ; + } + + priv->read_reg = pcan_read_canreg;
drivers/net/can/sja1000/peak_pcmcia.c line 535
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ priv->write_reg = pcan_write_canreg; + priv->can.clock.freq =DRV_CAN_CLOCK ; + priv->ocr =DRV_OCR ; + priv->cdr =DRV_CDR ; + priv->flags |=SJA1000_CUSTOM_IRQ_HANDLER ; + +/* register SJA1000 device */ + err =register_sja1000dev (netdev); +if (err) { +free_sja1000dev (netdev);
dito
Quoted 27 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +27
-0+continue ; + } + + card->channel[i].netdev = netdev; + card->chan_count++; + +/* set corresponding led on in the new ccr */ + ccr &= ~DRV_CCR_LED_OFF_CHAN (i); + +dev_info (&dev->dev, +"registered %s on channel %d at 0x%p irq %d\n" , + netdev->name, i, priv->reg_base, dev->irq); + } + +/* write new ccr (change leds state) */ +pcan_write_reg (card,DRV_CCR , ccr); + +return err; +} + +static int pcan_conf_check (struct pcmcia_device *dev,void *priv_data) +{ + dev->resource[0 ]->flags &= ~IO_DATA_PATH_WIDTH ; + dev->resource[0 ]->flags |=IO_DATA_PATH_WIDTH_8 ;/* only */ + dev->io_lines =10 ; + +/* This reserves IO space but doesn't actually enable it */
drivers/net/can/sja1000/peak_pcmcia.c line 572
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+return pcmcia_request_io (dev); +} + +/* +* free all resources used by the device +*/ +static void pcan_free (struct pcmcia_device *dev) +{ +if (!dev->priv) +return ;
Can this happen?
Quoted 20 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +20
-0+ +pcan_stop_led_timer (dev->priv); +free_irq (dev->irq, dev->priv); +pcan_free_channels (dev->priv); + +kfree (dev->priv); + dev->priv =NULL ; +} + +/* +* setup PCMCIA socket and probe for PEAK-System PC-CARD +*/ +static int __devinit pcan_probe (struct pcmcia_device *dev) +{ +struct pcan_pccard *card; +int err; + + dev->config_flags |=CONF_ENABLE_IRQ |CONF_AUTO_SET_IO ; + + err =pcmcia_loop_config (dev, pcan_conf_check,NULL );
drivers/net/can/sja1000/peak_pcmcia.c line 602
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+if (err) { +dev_err (&dev->dev,"pcmcia_loop_config() error %d\n" , err); + goto probe_err_1; + } + +dev_info (&dev->dev,"new PEAK-System pcmcia card detected:\n" ); + +dev_info (&dev->dev,"%s %s\n" , + dev->prod_id[0 ] ? dev->prod_id[0 ] :"PEAK-System" , + dev->prod_id[1 ] ? dev->prod_id[1 ] :"PCAN-PC Card" );
better make it only one dev_info(); there might be other printks interfering...
Quoted 96 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +95
-0+ +/* +* Note: +* base_port = ioport_addr = dev->resource[0]->start +* port_count = dev->resource[0]->end +*/ + +if (!dev->irq) { +dev_err (&dev->dev,"no irq assigned\n" ); + err = -ENODEV ; + goto probe_err_1; + } + + err =pcmcia_enable_device (dev); +if (err) { +dev_err (&dev->dev,"pcmcia_enable_device failed err=%d\n" , + err); + goto probe_err_1; + } + + card =kzalloc (sizeof (struct pcan_pccard ),GFP_KERNEL ); +if (!card) { +dev_err (&dev->dev,"kzalloc() failure\n" ); + err = -ENOMEM ; + goto probe_err_2; + } + + card->dev = dev; + dev->priv = card; + +/* sja1000 api uses iomem */ + card->ioport_addr =ioport_map (dev->resource[0 ]->start, +resource_size (dev->resource[0 ])); +if (!card->ioport_addr) { + err = -ENOMEM ; + goto probe_err_3; + } + +/* display firware version */ +dev_info (&dev->dev,"firmware %d.%d\n" , +pcan_read_reg (card,DRV_FW_MAJOR ), +pcan_read_reg (card,DRV_FW_MINOR )); + +/* detect available channels */ +pcan_add_channels (card); +if (!card->chan_count) + goto probe_err_3; + +/* init the timer which controls the leds */ +init_timer (&card->led_timer); + card->led_timer.function = pcan_led_timer; + card->led_timer.data = (unsigned long )card; + +/* request the given irq */ + err =request_irq (dev->irq, &pcan_isr,IRQF_SHARED ,DRV_NAME , card); +if (err) + goto probe_err_4; + +/* power on the connectors */ +pcan_set_can_power (card,1 ); + +return 0 ; + +probe_err_4: +/* unregister can devices from network */ +pcan_free_channels (card); + +probe_err_3: +kfree (card); + dev->priv =NULL ; + +probe_err_2: +pcmcia_disable_device (dev); + +probe_err_1: +return err; +} + +/* +* release claimed resources +*/ +static void pcan_remove (struct pcmcia_device *dev) +{ +pcan_free (dev); +pcmcia_disable_device (dev); +} + +static struct pcmcia_driver pcan_driver = { + .name =DRV_NAME , + .probe = pcan_probe, + .remove = pcan_remove, + .id_table = pcan_table, +}; + +static int __init pcan_init (void )
drivers/net/can/sja1000/peak_pcmcia.c line 707
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+{ +return pcmcia_register_driver (&pcan_driver); +} +module_init (pcan_init); + +static void __exit pcan_exit(void) +{ +pcmcia_unregister_driver (&pcan_driver); +} +module_exit (pcan_exit);
cheers, Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Hi Marc,
Please see my comments/notes below.
Quoted 4 lines · Marc Kleine-Budde
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Please remove the address. The FSF sometimes relocates it's office.
Done.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"Can you use the same name for the driver and the .c file?
Ok (peak_pccard)
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c line 45
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+ +/* PEAK-System PCMCIA driver version */ +#define DRV_VERSION_MAJOR 0 +#define DRV_VERSION_MINOR 2 +#define DRV_VERSION_SUBMINOR 0 + +#define DRV_VERSION_STRING __stringify(DRV_VERSION_MAJOR)"."\ + __stringify(DRV_VERSION_MINOR)"."\ + __stringify(DRV_VERSION_SUBMINOR)please add whitespace before "\"
This (obsolete) version string is now removed from the driver
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ +#define DRV_CHAN_SIZE 0x20 +#define DRV_CHAN_OFF (c) ((c)*DRV_CHAN_SIZE)please add whitespace before and after "*"
Ok.
Quoted 4 lines
Quoted 1 line
+#define
DRV_CDR(CDR_CBP|CDR_CLKOUT_MASK)Can you please properly align all the defines above (or don't align at all). I personally prefer a common prefix for all functions and defines used in a driver, maybe use
PCAN_instead ofDRV_
Ok (PCC_)
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+ +/* +* write a sja1000 register +*/ +static void pcan_write_canreg (const struct sja1000_priv *priv,int port,u8 v)In the functions below port is always u8, here an int.
Well, the sja1000 api defines an "int" arg as port value, while the other (static) functions "know" that this value will never exceed 255... But I agree with you, to be consistent, I changed all "u8" port defs into "int" one.
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c line 192
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+{ +struct pcan_pccard *card = priv->priv; +int c = (priv->reg_base - card->ioport_addr) /DRV_CHAN_SIZE ; + +/* sja1000 register changes control the leds state */ +switch (port) { +case REG_MOD :I would use:
if (port ==REG_MOD), instead of the outer switch.
Ok, this is a remainder of some other "catches" I did at the beginning. This is changed as you suggested now.
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c line 198
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+switch (v) { +case MOD_RM : +/* Reset Mode: set led on */ +pcan_set_leds (card,DRV_LED (c),DRV_LED_ON ); +break ; +case 0x00 :is there a defefine for
0x0, too?
Unfortunately, I didn't find any #define of the "normal mode" into drivers/net/can/sja1000/sja1000.h, so...
Quoted 12 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +12
-0+ +/* +* wait for SPI engine while it is busy +*/ +static int pcan_wait_spi_busy (struct pcan_pccard *card) +{ +int i; + +for (i =0 ; i<DRV_SPI_MAX_WAIT_LOOP ; i++) { +if (!(pcan_read_reg (card,DRV_CSR )&DRV_CSR_SPI_BUSY )) +break ; +schedule ();
Quoted 1 line
How long does it take? Can you use msleep or
usleep_rangehere?
TODO
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c line 246
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ } + +if (i>=DRV_SPI_MAX_WAIT_LOOP ) { +dev_err (&card->dev->dev,"failure: spi engine busy\n" );please use
netdev_err()
Hmmm... Dealing with SPI engine doesn't' concern any "canx" netdev interface. The board handles two (or more) channels. At that moment, which "canx" interface should be chosen? I'd prefer some prefix dealing with the bus in the output msg, rather than one dealing with "canx" interface... What is your opinion?
Quoted 11 lines
drivers/net/can/sja1000/peak_pcmcia.c line 262
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+/* +* write data in device eeprom +*/ +static int pcan_write_eeprom (struct pcan_pccard *card,u16 addr,u8 v) +{ +u8 status; +int err, i; + +/* write instruction */ +pcan_write_reg (card,DRV_SPI_INR ,0x06 );Can you define some macros for this and the following constants?
TODO
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ + +/* set address and data */ +pcan_write_reg (card,DRV_SPI_ADR , addr&0xff );The 3rd argument of
pcan_write_reg()is u8, so the0xffis not needed.
So it is (now, "ports" are int args ;-)
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c line 318
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+ +write_eeprom_err: +dev_info (&card->dev->dev, +"writing 0x%x in eeprom @0x%x failed (err %d)\n" , + v, addr, err);
netdev_info()
Same answer as above (doesn't deal with canx interface here). Which one should I choose?
Quoted 11 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +11
-0+/* +* set leds state according to channel activity +*/ +static void pcan_led_timer (unsigned long arg) +{ +struct pcan_pccard *card = (struct pcan_pccard *)arg; +struct net_device *netdev; +u8 ccr = card->ccr; +int i, up_count; + +for (i = up_count =0 ; i< card->chan_count; i++) {
Quoted 2 lines
Personally I would not initialize
up_countin thefor()loop, as it is unrelated to it.
Ok, init moved in above variable declaration.
Quoted 23 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +23
-0+/* +* free all resources used by the channels and switch off leds and can power +*/ +static void pcan_free_channels (struct pcan_pccard *card) +{ +int i; +u8 led_mask =0 ; + +for (i =0 ; i< card->chan_count; i++) { +struct net_device *netdev; +char name[IFNAMSIZ ]; + + led_mask |=DRV_LED (i); + + netdev = card->channel[i].netdev; +if (!netdev) +continue ; + +strncpy (name, netdev->name,IFNAMSIZ ); +unregister_sja1000dev (netdev); +free_sja1000dev (netdev); + +dev_info (&card->dev->dev,"%s removed\n" , name);
Quoted 1 line
netdev_info()...maybe remove altogether
Hmm... At that time, the netdev pointer is no more valid, isn't it? And personally, I prefer a msg prefixed by a bus notification telling that one of its "children" doesn't exist anymore... (never good for a dead thing to talk, you know ;-) But once again, what is the general/linux-can rule?
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+static int pcan_add_channels (struct pcan_pccard *card) +{ +struct pcmcia_device *dev = card->dev; +int i, err; +u8 ccr =DRV_CCR_INIT ; +unsigned long rst_time; ^^^^^^^^this var is used write only, please remove.
Ok, you're right, I forgot it. It is removed now.
Quoted 4 lines
(quoted diff) +2
-0+ /* create one network device per channel detected */ + for (i = 0; i< DRV_CHAN_MAX; i++) {For documentation reasons I suggest to use
ARRAY_SIZE(card->channel)instead ofDRV_CHAN_MAX.
Yes, ok. I think the ems_pcmcia.c file should be updated too.
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 506
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+struct net_device *netdev; +struct sja1000_priv *priv; + + netdev =alloc_sja1000dev (0 ); +if (!netdev) { + err = -ENOMEM ; +break ;please do a proper cleanup if this fails with i != 0.
The cleaning is done after the call to "pcan_add_channels()" in "pcan_probe()", when the count of detected channels is 0.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c line 521
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+if (!pcan_check_channel (priv)) { +dev_err (&dev->dev,"channel %d not present\n" , i); +free_sja1000dev (netdev);same here
See above
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c line 535
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+/* register SJA1000 device */ + err =register_sja1000dev (netdev); +if (err) { +free_sja1000dev (netdev);dito
See above
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c line 572
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+ +/* +* free all resources used by the device +*/ +static void pcan_free (struct pcmcia_device *dev) +{ +if (!dev->priv) +return ;Can this happen?
Mainly to protect from multiple calls...
Quoted 15 lines
Quoted 15 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +15
-0+/* +* setup PCMCIA socket and probe for PEAK-System PC-CARD +*/ +static int __devinit pcan_probe (struct pcmcia_device *dev) +{ +struct pcan_pccard *card; +int err; + + dev->config_flags |=CONF_ENABLE_IRQ |CONF_AUTO_SET_IO ; + + err =pcmcia_loop_config (dev, pcan_conf_check,NULL ); +if (err) { +dev_err (&dev->dev,"pcmcia_loop_config() error %d\n" , err); + goto probe_err_1; + }
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 602
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+ +dev_info (&dev->dev,"new PEAK-System pcmcia card detected:\n" ); + +dev_info (&dev->dev,"%s %s\n" , + dev->prod_id[0 ] ? dev->prod_id[0 ] :"PEAK-System" , + dev->prod_id[1 ] ? dev->prod_id[1 ] :"PCAN-PC Card" );better make it only one
dev_info(); there might be other printks interfering...
Yes ok, but I'm not sure whether the line won't be too large for a 80 columns screen.
Quoted 1 line
cheers, Marc
Thanks for your time.
Best regards,
Stéphane
Hi Stephane,
please send a patch using a proper subject line and commit message. Also add a CC to the pcmcia linux mailing list. Thanks.
Quoted 5 lines · Stephane Grosjean
Hi,
Please find below a new patch which goal is to include the support of the PEAK-System PCMCIA board PCAN-PC Card. This board is SJA1000 based and is available as a single or dual CAN channel version.
Nice, I have such a pcmcia card...
Quoted 62 lines
drivers/net/can/sja1000/Kconfig +7
-0@@ -43,6 +43,13 @@ config CAN_EMS_PCI CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). +config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card" + depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCIdrivers/net/can/sja1000/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o obj-$(CONFIG_CAN_TSCAN1) += tscan1.odrivers/net/can/sja1000/peak_pcmcia.c new file +26
-0@@ -0,0 +1,707 @@ +/* +* CAN driver for PEAK-System PCAN-PCARD +* Derived from the PCAN project file driver/src/pcan_pccard.c +* +* Copyright (C) 2006-2009 PEAK System-Technik GmbH +* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the version 2 of the GNU General Public License +* as published by the Free Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/netdevice.h> +#include <linux/delay.h> +#include <linux/timer.h>
drivers/net/can/sja1000/peak_pcmcia.c line 36
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+#include <linux/io.h> +#include <pcmcia/cistpl.h> +#include <pcmcia/ds.h> +#include <linux/can.h> +#include <linux/can/dev.h> +#include <linux/stringify.h> +#include "sja1000.h" + +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"
I find the mix of "peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.
drivers/net/can/sja1000/peak_pcmcia.c line 45
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+ +/* PEAK-System PCMCIA driver version */ +#define DRV_VERSION_MAJOR 0 +#define DRV_VERSION_MINOR 2 +#define DRV_VERSION_SUBMINOR 0 + +#define DRV_VERSION_STRING __stringify(DRV_VERSION_MAJOR)"."\ + __stringify(DRV_VERSION_MINOR)"."\ + __stringify(DRV_VERSION_SUBMINOR)
As for the USB driver, I would remove this redundant versioning stuff. Also version 0.2.0 does not really sound like like a stable piece of software.
drivers/net/can/sja1000/peak_pcmcia.c line 55
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_DESCRIPTION ("CAN driver for PEAK-System PCAN-PC Cards" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_SUPPORTED_DEVICE ("PEAK PCAN-PC Card" ); +MODULE_VERSION (DRV_VERSION_STRING ); + +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2)
Hm, the prefix DRV_ here and below does not really make sense. But well, it's a minor issue.
drivers/net/can/sja1000/peak_pcmcia.c line 61
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+#define DRV_MANF_ID 0x0377 +#define DRV_CARD_ID 0x0001 + +#define DRV_CHAN_SIZE 0x20 +#define DRV_CHAN_OFF (c) ((c)*DRV_CHAN_SIZE)
Spaces around "*"
drivers/net/can/sja1000/peak_pcmcia.c line 62
Quoted 1 line
drivers/net/can/sja1000/peak_pcmcia.c new file +1
-0+#define DRV_COMN_OFF (DRV_CHAN_OFF(DRV_CHAN_MAX))
Please align with tabs and remove "()".
drivers/net/can/sja1000/peak_pcmcia.c line 68
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+#define DRV_COMN_SIZE 0x40 + +/* common area registers */ +#define DRV_CCR 0x00 +#define DRV_CSR 0x02 +#define DRV_CPR 0x04
Add tabs for the 3 lines above.
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+#define DRV_SPI_DIR 0x06 +#define DRV_SPI_DOR 0x08 +#define DRV_SPI_ADR 0x0a +#define DRV_SPI_INR 0x0c +#define DRV_FW_MAJOR 0x10 +#define DRV_FW_MINOR 0x12 + +/* CCR bits */ +#define DRV_CCR_CLK_16 0x00 +#define DRV_CCR_CLK_10 0x01
drivers/net/can/sja1000/peak_pcmcia.c line 88
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+#define DRV_CCR_CLK_21 0x02 +#define DRV_CCR_CLK_8 0x03 +#define DRV_CCR_CLK_MASK DRV_CCR_CLK_8 + +#define DRV_CCR_RST_CHAN (c) (0x01 << ((c) + 2)) +#define DRV_CCR_RST_ALL (DRV_CCR_RST_CHAN(0) | DRV_CCR_RST_CHAN(1)) +#define DRV_CCR_RST_MASK DRV_CCR_RST_ALL + +/* led selection bits */ +#define DRV_LED (c) (1 << (c))
Tabs?
drivers/net/can/sja1000/peak_pcmcia.c line 95
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+#define DRV_LED_ALL (DRV_LED(0) | DRV_LED(1)) + +/* led state value */ +#define DRV_LED_ON 0x00 +#define DRV_LED_FAST 0x01 +#define DRV_LED_SLOW 0x02 +#define DRV_LED_OFF 0x03
Please align as all other #defines.
drivers/net/can/sja1000/peak_pcmcia.c line 106
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+#define DRV_CCR_LED_CHAN (s, c) ((s) << (((c) + 2) << 1)) + +#define DRV_CCR_LED_ON_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_ON, c) +#define DRV_CCR_LED_FAST_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_FAST, c) +#define DRV_CCR_LED_SLOW_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_SLOW, c) +#define DRV_CCR_LED_OFF_CHAN (c) DRV_CCR_LED_CHAN(DRV_LED_OFF, c) +#define DRV_CCR_LED_MASK_CHAN (c) DRV_CCR_LED_OFF_CHAN(c) +#define DRV_CCR_LED_OFF_ALL (DRV_CCR_LED_OFF_CHAN(0) | \ + DRV_CCR_LED_OFF_CHAN(1)) +#define DRV_CCR_LED_MASK DRV_CCR_LED_OFF_ALL
Ditto.
drivers/net/can/sja1000/peak_pcmcia.c line 108
Quoted 1 line
drivers/net/can/sja1000/peak_pcmcia.c new file +1
-0+#define DRV_CCR_INIT (DRV_CCR_CLK_16 | DRV_CCR_RST_ALL | DRV_CCR_LED_OFF_ALL)
Ditto
drivers/net/can/sja1000/peak_pcmcia.c line 112
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+#define DRV_CSR_SPI_BUSY 0x04 +#define DRV_SPI_MAX_WAIT_LOOP 100 +#define DRV_WRITE_MAX_LOOP 1000
Ditto
drivers/net/can/sja1000/peak_pcmcia.c line 122
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+/* +* The board configuration is probably following: +* RX1 is connected to ground. +* TX1 is not connected. +* CLKO is not connected. +* Setting the OCR register to 0xDA is a good idea. +* This means normal output mode, push-pull and the correct polarity. +*/ +#define DRV_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
Ditto
drivers/net/can/sja1000/peak_pcmcia.c line 130
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+ +/* +* In the CDR register, you should set CBP to 1. +* You will probably also want to set the clock divider value to 7 +* (meaning direct oscillator output) because the second SJA1000 chip +* is driven by the first one CLKOUT output. +*/ +#define DRV_CDR (CDR_CBP | CDR_CLKOUT_MASK)
Ditto
Quoted 122 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +122
-0+ +struct pcan_channel { +struct net_device *netdev; +unsigned long prev_rx_bytes; +unsigned long prev_tx_bytes; +}; + +/* PCAN-PC Card private structure */ +struct pcan_pccard { +struct pcmcia_device *dev; +int chan_count; +struct pcan_channel channel[DRV_CHAN_MAX ]; +u8 ccr; +void __iomem *ioport_addr; +struct timer_list led_timer; +}; + +static struct pcmcia_device_id pcan_table[] = { +PCMCIA_DEVICE_MANF_CARD (DRV_MANF_ID ,DRV_CARD_ID ), +PCMCIA_DEVICE_NULL , +}; + +MODULE_DEVICE_TABLE (pcmcia, pcan_table); + +static void pcan_set_leds (struct pcan_pccard *card,u8 mask,u8 state); + +/* +* start timer which controls leds state +*/ +static void pcan_start_led_timer (struct pcan_pccard *card) +{ +if (!timer_pending (&card->led_timer)) +mod_timer (&card->led_timer, jiffies +HZ ); +} + +/* +* stop the timer which controls leds state +*/ +static void pcan_stop_led_timer (struct pcan_pccard *card) +{ +del_timer_sync (&card->led_timer); +} + +/* +* read a sja1000 register +*/ +static u8 pcan_read_canreg (const struct sja1000_priv *priv,int port) +{ +return ioread8 (priv->reg_base + port); +} + +/* +* write a sja1000 register +*/ +static void pcan_write_canreg (const struct sja1000_priv *priv,int port,u8 v) +{ +struct pcan_pccard *card = priv->priv; +int c = (priv->reg_base - card->ioport_addr) /DRV_CHAN_SIZE ; + +/* sja1000 register changes control the leds state */ +switch (port) { +case REG_MOD : +switch (v) { +case MOD_RM : +/* Reset Mode: set led on */ +pcan_set_leds (card,DRV_LED (c),DRV_LED_ON ); +break ; +case 0x00 : +/* Normal Mode: led slow blinking and start led timer */ +pcan_set_leds (card,DRV_LED (c),DRV_LED_SLOW ); +pcan_start_led_timer (card); +break ; + } +break ; + } +iowrite8 (v, priv->reg_base + port); +} + +/* +* read a register from the common area +*/ +static u8 pcan_read_reg (struct pcan_pccard *card,u8 port) +{ +return ioread8 (card->ioport_addr +DRV_COMN_OFF + port); +} + +/* +* write a register into the common area +*/ +static void pcan_write_reg (struct pcan_pccard *card,u8 port,u8 v) +{ +/* cache ccr value */ +if (port ==DRV_CCR ) { +if (card->ccr == v) +return ; + card->ccr = v; + } + +iowrite8 (v, card->ioport_addr +DRV_COMN_OFF + port); +} + +/* +* wait for SPI engine while it is busy +*/ +static int pcan_wait_spi_busy (struct pcan_pccard *card) +{ +int i; + +for (i =0 ; i <DRV_SPI_MAX_WAIT_LOOP ; i++) { +if (!(pcan_read_reg (card,DRV_CSR ) &DRV_CSR_SPI_BUSY )) +break ; +schedule (); + } + +if (i >=DRV_SPI_MAX_WAIT_LOOP ) { +dev_err (&card->dev->dev,"failure: spi engine busy\n" ); +return -EIO ; + } + +return 0 ; +} +
drivers/net/can/sja1000/peak_pcmcia.c line 262
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+/* +* write data in device eeprom +*/ +static int pcan_write_eeprom (struct pcan_pccard *card,u16 addr,u8 v) +{ +u8 status; +int err, i; + +/* write instruction */ +pcan_write_reg (card,DRV_SPI_INR ,0x06 );
Macro definitons would be nice.
drivers/net/can/sja1000/peak_pcmcia.c line 269
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+ err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; + +/* wait until write enable */ +for (i =0 ; i <DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */
This comment does not tell me anything.
drivers/net/can/sja1000/peak_pcmcia.c line 274
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+pcan_write_reg (card,DRV_SPI_INR ,0x05 ); + err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; +/* WEL */
Ditto.
drivers/net/can/sja1000/peak_pcmcia.c line 276
Quoted 2 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +2
-0+ status =pcan_read_reg (card,DRV_SPI_DIR ); +if (status &0x02 )
Macro definitions would be nice here and in other places to better understand the code.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+break ; + } + +if (i >=DRV_WRITE_MAX_LOOP ) {
drivers/net/can/sja1000/peak_pcmcia.c line 290
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ err = -EIO ; + goto write_eeprom_err; + } + +/* set address and data */ +pcan_write_reg (card,DRV_SPI_ADR , addr &0xff ); +pcan_write_reg (card,DRV_SPI_DOR , v); + +/* write instruction with bit3 set accoridng to address */ +pcan_write_reg (card,DRV_SPI_INR , ((addr &0x100 ) ?8 :0 ) |0x02 );
Ditto.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; +
drivers/net/can/sja1000/peak_pcmcia.c line 304
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+/* wait while write in progress */ +for (i =0 ; i <DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */ +pcan_write_reg (card,DRV_SPI_INR ,0x05 ); + err =pcan_wait_spi_busy (card); +if (err) + goto write_eeprom_err; + + status =pcan_read_reg (card,DRV_SPI_DIR ); +if (!(status &0x01 ))
Ditto.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+break ; + } + +if (i >=DRV_WRITE_MAX_LOOP ) {
drivers/net/can/sja1000/peak_pcmcia.c line 318
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ err = -EIO ; + goto write_eeprom_err; + } + +return 0 ; + +write_eeprom_err: +dev_info (&card->dev->dev, +"writing 0x%x in eeprom @0x%x failed (err %d)\n" , + v, addr, err);
Info or error. Can this happen? If yes, how often?
drivers/net/can/sja1000/peak_pcmcia.c line 327
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+return err; +} + +/* +* control the leds +* @led_mask: should be an or made of DRV_LED(x) +* @state: DRV_LED_ON, DRV_LED_OFF, DRV_LED_SLOW or DRV_LED_FAST +*/
Please remove the docbook tags.
Quoted 89 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +89
-0+static void pcan_set_leds (struct pcan_pccard *card,u8 led_mask,u8 state) +{ +u8 ccr = card->ccr; +int i; + +for (i =0 ; i < card->chan_count; i++) +if (led_mask &DRV_LED (i)) { +/* clear corresponding led bits in ccr */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); +/* then set new bits */ + ccr |=DRV_CCR_LED_CHAN (state, i); + } + +/* real write only if something has changed in ccr */ +pcan_write_reg (card,DRV_CCR , ccr); +} + +/* +* enable/disable CAN connector power +*/ +static inline void pcan_set_can_power (struct pcan_pccard *card,int onoff) +{ +pcan_write_eeprom (card,0 , (onoff) ?1 :0 ); +} + +/* +* set leds state according to channel activity +*/ +static void pcan_led_timer (unsigned long arg) +{ +struct pcan_pccard *card = (struct pcan_pccard *)arg; +struct net_device *netdev; +u8 ccr = card->ccr; +int i, up_count; + +for (i = up_count =0 ; i < card->chan_count; i++) { +/* default is: not configured */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_ON_CHAN (i); + + netdev = card->channel[i].netdev; +if (!netdev || !(netdev->flags &IFF_UP )) +continue ; + + up_count++; + +/* no activity (but configured) */ + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_SLOW_CHAN (i); + +/* if bytes counters changed, set fast blinking led */ +if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) { + card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes; + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_FAST_CHAN (i); + } +if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) { + card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes; + ccr &= ~DRV_CCR_LED_MASK_CHAN (i); + ccr |=DRV_CCR_LED_FAST_CHAN (i); + } + } + +/* write the new leds state */ +pcan_write_reg (card,DRV_CCR , ccr); + +/* restart timer (except if no more configured channels) */ +if (up_count) +mod_timer (&card->led_timer, jiffies +HZ ); +} + +/* +* interrupt service routine +*/ +static irqreturn_t pcan_isr (int irq,void *dev_id) +{ +struct pcan_pccard *card = dev_id; +struct net_device *netdev; +irqreturn_t retval =IRQ_NONE ; +int i, again; + + do { + again = 0; + + /* Check interrupt for each channel */ + for (i = 0; i < card->chan_count; i++) { + netdev = card->channel[i].netdev; + if (!netdev) + continue;
drivers/net/can/sja1000/peak_pcmcia.c line 426
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ +if (sja1000_interrupt (irq, netdev) ==IRQ_HANDLED ) + again =1 ; + } + +/* At least one channel handled the interrupt */ +if (again) + retval =IRQ_HANDLED ; + + }while (again);
I wonder if it makes sense to limit the loop count.
Quoted 165 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +165
-0+return retval; +} + +/* +* free all resources used by the channels and switch off leds and can power +*/ +static void pcan_free_channels (struct pcan_pccard *card) +{ +int i; +u8 led_mask =0 ; + +for (i =0 ; i < card->chan_count; i++) { +struct net_device *netdev; +char name[IFNAMSIZ ]; + + led_mask |=DRV_LED (i); + + netdev = card->channel[i].netdev; +if (!netdev) +continue ; + +strncpy (name, netdev->name,IFNAMSIZ ); +unregister_sja1000dev (netdev); +free_sja1000dev (netdev); + +dev_info (&card->dev->dev,"%s removed\n" , name); + } + +if (pcmcia_dev_present (card->dev)) { +pcan_set_leds (card, led_mask,DRV_LED_OFF ); +pcan_set_can_power (card,0 ); + } + +ioport_unmap (card->ioport_addr); +} + +/* +* check if a CAN controller is present at the specified location +*/ +static inline int pcan_check_channel (struct sja1000_priv *priv) +{ +/* make sure SJA1000 is in reset mode */ +pcan_write_canreg (priv,REG_MOD ,1 ); +pcan_write_canreg (priv,REG_CDR ,CDR_PELICAN ); + +/* read reset-values */ +if (pcan_read_canreg (priv,REG_CDR ) ==CDR_PELICAN ) +return 1 ; + +return 0 ; +} + +static int pcan_add_channels (struct pcan_pccard *card) +{ +struct pcmcia_device *dev = card->dev; +int i, err; +u8 ccr =DRV_CCR_INIT ; +unsigned long rst_time; + +/* init common registers (reset channels and leds off) */ + card->ccr = ~ccr; +pcan_write_reg (card,DRV_CCR , ccr); + rst_time = jiffies; + +/* wait 2ms before unresetting channels */ +mdelay (2 ); + + ccr &= ~DRV_CCR_RST_ALL ; +pcan_write_reg (card,DRV_CCR , ccr); + +/* create one network device per channel detected */ +for (i =0 ; i <DRV_CHAN_MAX ; i++) { +struct net_device *netdev; +struct sja1000_priv *priv; + + netdev =alloc_sja1000dev (0 ); +if (!netdev) { + err = -ENOMEM ; +break ; + } + +/* update linkages */ + priv =netdev_priv (netdev); + priv->priv = card; +SET_NETDEV_DEV (netdev, &dev->dev); + + priv->irq_flags =IRQF_SHARED ; + netdev->irq = dev->irq; + priv->reg_base = card->ioport_addr +DRV_CHAN_OFF (i); + +/* check if channel is present */ +if (!pcan_check_channel (priv)) { +dev_err (&dev->dev,"channel %d not present\n" , i); +free_sja1000dev (netdev); +continue ; + } + + priv->read_reg = pcan_read_canreg; + priv->write_reg = pcan_write_canreg; + priv->can.clock.freq =DRV_CAN_CLOCK ; + priv->ocr =DRV_OCR ; + priv->cdr =DRV_CDR ; + priv->flags |=SJA1000_CUSTOM_IRQ_HANDLER ; + +/* register SJA1000 device */ + err =register_sja1000dev (netdev); +if (err) { +free_sja1000dev (netdev); +continue ; + } + + card->channel[i].netdev = netdev; + card->chan_count++; + +/* set corresponding led on in the new ccr */ + ccr &= ~DRV_CCR_LED_OFF_CHAN (i); + +dev_info (&dev->dev, +"registered %s on channel %d at 0x%p irq %d\n" , + netdev->name, i, priv->reg_base, dev->irq); + } + +/* write new ccr (change leds state) */ +pcan_write_reg (card,DRV_CCR , ccr); + +return err; +} + +static int pcan_conf_check (struct pcmcia_device *dev,void *priv_data) +{ + dev->resource[0 ]->flags &= ~IO_DATA_PATH_WIDTH ; + dev->resource[0 ]->flags |=IO_DATA_PATH_WIDTH_8 ;/* only */ + dev->io_lines =10 ; + +/* This reserves IO space but doesn't actually enable it */ +return pcmcia_request_io (dev); +} + +/* +* free all resources used by the device +*/ +static void pcan_free (struct pcmcia_device *dev) +{ +if (!dev->priv) +return ; + +pcan_stop_led_timer (dev->priv); +free_irq (dev->irq, dev->priv); +pcan_free_channels (dev->priv); + +kfree (dev->priv); + dev->priv =NULL ; +} + +/* +* setup PCMCIA socket and probe for PEAK-System PC-CARD +*/ +static int __devinit pcan_probe (struct pcmcia_device *dev) +{ +struct pcan_pccard *card; +int err; + + dev->config_flags |=CONF_ENABLE_IRQ |CONF_AUTO_SET_IO ; + + err =pcmcia_loop_config (dev, pcan_conf_check,NULL );
drivers/net/can/sja1000/peak_pcmcia.c line 602
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+if (err) { +dev_err (&dev->dev,"pcmcia_loop_config() error %d\n" , err); + goto probe_err_1; + } + +dev_info (&dev->dev,"new PEAK-System pcmcia card detected:\n" ); + +dev_info (&dev->dev,"%s %s\n" , + dev->prod_id[0 ] ? dev->prod_id[0 ] :"PEAK-System" , + dev->prod_id[1 ] ? dev->prod_id[1 ] :"PCAN-PC Card" );
One line (dev_info) should be enough. Also "dev->dev" is not really readable. "dev->p[cmcia_]dev" would be much better.
Quoted 13 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +13
-0+ +/* +* Note: +* base_port = ioport_addr = dev->resource[0]->start +* port_count = dev->resource[0]->end +*/ + +if (!dev->irq) { +dev_err (&dev->dev,"no irq assigned\n" ); + err = -ENODEV ; + goto probe_err_1; + } +
drivers/net/can/sja1000/peak_pcmcia.c line 625
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ err =pcmcia_enable_device (dev); +if (err) { +dev_err (&dev->dev,"pcmcia_enable_device failed err=%d\n" , + err); + goto probe_err_1; + } + + card =kzalloc (sizeof (struct pcan_pccard ),GFP_KERNEL ); +if (!card) { +dev_err (&dev->dev,"kzalloc() failure\n" );
Please be more specific, e.g.: "couldn't allocated card memory".
Quoted 43 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +43
-0+ err = -ENOMEM ; + goto probe_err_2; + } + + card->dev = dev; + dev->priv = card; + +/* sja1000 api uses iomem */ + card->ioport_addr =ioport_map (dev->resource[0 ]->start, +resource_size (dev->resource[0 ])); +if (!card->ioport_addr) { + err = -ENOMEM ; + goto probe_err_3; + } + +/* display firware version */ +dev_info (&dev->dev,"firmware %d.%d\n" , +pcan_read_reg (card,DRV_FW_MAJOR ), +pcan_read_reg (card,DRV_FW_MINOR )); + +/* detect available channels */ +pcan_add_channels (card); +if (!card->chan_count) + goto probe_err_3; + +/* init the timer which controls the leds */ +init_timer (&card->led_timer); + card->led_timer.function = pcan_led_timer; + card->led_timer.data = (unsigned long )card; + +/* request the given irq */ + err =request_irq (dev->irq, &pcan_isr,IRQF_SHARED ,DRV_NAME , card); +if (err) + goto probe_err_4; + +/* power on the connectors */ +pcan_set_can_power (card,1 ); + +return 0 ; + +probe_err_4: +/* unregister can devices from network */ +pcan_free_channels (card);
drivers/net/can/sja1000/peak_pcmcia.c line 678
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+ +probe_err_3: +kfree (card); + dev->priv =NULL ; + +probe_err_2: +pcmcia_disable_device (dev); + +probe_err_1: +return err;
I'm missing ioport_unmap()!
Quoted 19 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +19
-0+} + +/* +* release claimed resources +*/ +static void pcan_remove (struct pcmcia_device *dev) +{ +pcan_free (dev); +pcmcia_disable_device (dev); +} + +static struct pcmcia_driver pcan_driver = { + .name =DRV_NAME , + .probe = pcan_probe, + .remove = pcan_remove, + .id_table = pcan_table, +}; + +static int __init pcan_init (void )
drivers/net/can/sja1000/peak_pcmcia.c line 707
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+{ +return pcmcia_register_driver (&pcan_driver); +} +module_init (pcan_init); + +static void __exit pcan_exit(void) +{ +pcmcia_unregister_driver (&pcan_driver); +} +module_exit (pcan_exit);
Thanks for your contribution.
Wolfgang.
Quoted 5 lines · Wolfgang Grandegger
Hi Stephane,
please send a patch using a proper subject line and commit message. Also add a CC to the pcmcia linux mailing list. Thanks.
Quoted 8 lines
Quoted 5 lines · Stephane Grosjean
Hi,
Please find below a new patch which goal is to include the support of the PEAK-System PCMCIA board PCAN-PC Card. This board is SJA1000 based and is available as a single or dual CAN channel version.
Nice, I have such a pcmcia card...
Yes. Me too :-)
Quoted 11 lines
drivers/net/can/sja1000/Kconfig config CAN_EMS_PCI · line 47
Quoted 11 lines
drivers/net/can/sja1000/Kconfig +2
-0@@ -43,6 +43,13 @@ config CAN_EMS_PCI CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). +config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card"
tristate "PEAK PCAN PC-Card (PCMCIA)"
??
Should we probably put all PCMCIA cards into a separate
linux/drivers/net/can/sja1000/pcmcia
directory - like we have it for the USB devices?
Quoted 9 lines
Quoted 9 lines
drivers/net/can/sja1000/Kconfig +5
-0+ depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCIdrivers/net/can/sja1000/Makefile +0
-0
Quoted 8 lines
drivers/net/can/sja1000/Makefile obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o · line 12
Quoted 8 lines
index 0604f24..b3d05cb 100644
drivers/net/can/sja1000/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o
This should be the module/driver name too.
Quoted 11 lines
drivers/net/can/sja1000/peak_pcmcia.c line 2
Quoted 11 lines
drivers/net/can/sja1000/Makefile +0
-0obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o obj-$(CONFIG_CAN_TSCAN1) += tscan1.odrivers/net/can/sja1000/peak_pcmcia.c new file +2
-0@@ -0,0 +1,707 @@ +/* +* CAN driver for PEAK-System PCAN-PCARD
PCAN-PC Card
as written on the PEAK website
Quoted 10 lines
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +10
-0+* Derived from the PCAN project file driver/src/pcan_pccard.c +* +* Copyright (C) 2006-2009 PEAK System-Technik GmbH +* Copyright (C) 2010-2012 Stephane Grosjean <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the version 2 of the GNU General Public License +* as published by the Free Software Foundation +* +* This program is distributed in the hope that it will be useful,
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 20
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/
Remove address info.
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c line 36
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.
Yep - peak_pcmcia
Quoted 14 lines
drivers/net/can/sja1000/peak_pcmcia.c line 45
Quoted 10 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+ +/* PEAK-System PCMCIA driver version */ +#define DRV_VERSION_MAJOR 0 +#define DRV_VERSION_MINOR 2 +#define DRV_VERSION_SUBMINOR 0 + +#define DRV_VERSION_STRING __stringify(DRV_VERSION_MAJOR)"."\ + __stringify(DRV_VERSION_MINOR)"."\ + __stringify(DRV_VERSION_SUBMINOR)As for the USB driver, I would remove this redundant versioning stuff. Also version 0.2.0 does not really sound like like a stable piece of software.
Dave Miller stated that driver versions are obsolete in Mainline.
Quoted 14 lines
drivers/net/can/sja1000/peak_pcmcia.c line 55
Quoted 11 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +9
-0+MODULE_AUTHOR ("Stephane Grosjean <[email protected]>" ); +MODULE_DESCRIPTION ("CAN driver for PEAK-System PCAN-PC Cards" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_SUPPORTED_DEVICE ("PEAK PCAN-PC Card" ); +MODULE_VERSION (DRV_VERSION_STRING ); + +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2)Hm, the prefix
DRV_here and below does not really make sense. But well, it's a minor issue.
ack. Remove DRV_ or rename it so someting like to PCC_
No more nitpicks in additions to Wolfgangs remarks.
Tnx & best regards,
Oliver
Quoted 5 lines · Oliver Hartkopp
Quoted 1 line · Wolfgang Grandegger
Nice, I have such a pcmcia card...
Yes. Me too :-)
Happy to please you :-))
Quoted 7 lines
drivers/net/can/sja1000/Kconfig +2
-0+config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card"tristate "PEAK PCAN PC-Card (PCMCIA)"
??
Please confirm: you'd like me to add the "(PCMCIA)" string at the end of the menu text, wouldn't you?
Quoted 5 lines
Should we probably put all PCMCIA cards into a separate
linux/drivers/net/can/sja1000/pcmcia
directory - like we have it for the USB devices?
If my Humble Opinion may help you: not sure this will be lots of other pcmcia (can) adapters in the future...
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/can/sja1000/Kconfig +5
-0+ depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCIdrivers/net/can/sja1000/Makefile +0
-0Quoted 8 lines
drivers/net/can/sja1000/Makefile obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o · line 12
Quoted 8 lines
index 0604f24..b3d05cb 100644
drivers/net/can/sja1000/Makefile +1
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.oThis should be the module/driver name too.
Quoted 7 lines
Quoted 5 lines
drivers/net/can/sja1000/Makefile obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o · line 15
Quoted 3 lines
drivers/net/can/sja1000/Makefile +3
-0+ +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.Yep -
peak_pcmcia
We just finished to talk about that and, as far as the PCAN-PC Card is a PC-CARD (16bit), we'd like to use the "peak_pccard" text for the module/module file/source file names instead of "peak_pcmcia". Related question: I suppose I'll have to change the "CONFIG_CAN_PEAK_PCMCIA" into "CONFIG_CAN_PEAK_PCCARD" too.
Please confirm.
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2)Quoted 2 lines
Hm, the prefix
DRV_here and below does not really make sense. But well, it's a minor issue.ack. Remove
DRV_or rename it so someting like toPCC_
Ok, changed to "PCC_" prefix.
Quoted 1 line
No more nitpicks in additions to Wolfgangs remarks.
Just one last question: FYI, I built the peak_pcmcia.c starting from peak_pci.c, so I suppose that the DRV_ prefix should be changed into that file too.
Quoted 2 lines
Tnx& best regards,
Oliver
Many thanks for all!
Best regards,
Stéphane
Hi Stephane,
Quoted 15 lines · Grosjean Stephane
Quoted 5 lines · Oliver Hartkopp
Quoted 1 line · Wolfgang Grandegger
Nice, I have such a pcmcia card...
Yes. Me too :-)
Happy to please you :-))
Quoted 4 lines
drivers/net/can/sja1000/Kconfig +2
-0+config CAN_PEAK_PCMCIA + tristate "PEAK PCAN PC-CARD Card"
Quoted 6 lines
Quoted 3 lines
tristate "PEAK PCAN PC-Card (PCMCIA)"
??
Please confirm: you'd like me to add the "(PCMCIA)" string at the end of the menu text, wouldn't you?
I think "PEAK PCAN PC-Card" is already pretty clear.
Quoted 8 lines
Quoted 5 lines
Should we probably put all PCMCIA cards into a separate
linux/drivers/net/can/sja1000/pcmcia
directory - like we have it for the USB devices?
If my Humble Opinion may help you: not sure this will be lots of other pcmcia (can) adapters in the future...
I agree. Let's wait and see.
Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/can/sja1000/Kconfig +3
-0+ depends on PCMCIA + ---help--- + This driver is for the PCAN PC-CARD PCMCIA card with 1 or 2channels
drivers/net/can/sja1000/Kconfig +2
-0+ from PEAK Systems (http://www.peak-system.com). + config CAN_PEAK_PCI tristate "PEAK PCAN PCI/PCIe Cards" depends on PCIdrivers/net/can/sja1000/Makefile +0
-0Quoted 8 lines
Quoted 8 lines
drivers/net/can/sja1000/Makefile +0
-0@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) +=sja1000_of_platform.o
obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o
obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o
obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
+obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.oThis should be the module/driver name too.
Quoted 5 lines
drivers/net/can/sja1000/Makefile
Quoted 3 lines
drivers/net/can/sja1000/Makefile +3
-0+ +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.
Quoted 8 lines
Quoted 1 line
Yep -
peak_pcmciaWe just finished to talk about that and, as far as the PCAN-PC Card is a PC-CARD (16bit), we'd like to use the "
peak_pccard" text for the module/module file/source file names instead of "peak_pcmcia". Related question: I suppose I'll have to change the "CONFIG_CAN_PEAK_PCMCIA" into "CONFIG_CAN_PEAK_PCCARD" too. Please confirm.
Yes, #defines, file names and prefixes should be consistently used.
Quoted 9 lines
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2)Quoted 2 lines
Hm, the prefix
DRV_here and below does not really make sense. But well, it's a minor issue.ack. Remove
DRV_or rename it so someting like toPCC_
Quoted 7 lines
Ok, changed to "
PCC_" prefix.Quoted 1 line
No more nitpicks in additions to Wolfgangs remarks.
Just one last question: FYI, I built the
peak_pcmcia.cstarting frompeak_pci.c, so I suppose that theDRV_prefix should be changed into that file too.
Well, it's me who pushed that driver to mainline ;-). Anyway, the prefix is bad but not worth to prepare or reject a patch.
Wolfgang.
Quoted 8 lines · Grosjean Stephane
Quoted 5 lines
+config
CAN_PEAK_PCMCIA+ tristate "PEAK PCAN PC-CARD Card"tristate "PEAK PCAN PC-Card (PCMCIA)"
??
Please confirm: you'd like me to add the "(PCMCIA)" string at the end of the menu text, wouldn't you?
I read some more Kconfigs to check the current handling in other drivers.
I think
tristate "PEAK PCAN PC-Card"
is better - and reflects the PEAK adapter name (note the upper/lower case!). Although the Kconfig entry is only visible when PCMCIA is enabled.
Quoted 9 lines
Quoted 6 lines
Should we probably put all PCMCIA cards into a separate
linux/drivers/net/can/sja1000/pcmcia
directory - like we have it for the USB devices?
If my Humble Opinion may help you: not sure this will be lots of other pcmcia (can) adapters in the future...
ok. Forget it :-)
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ depends on PCMCIA + ---help--- + This driver is for the
PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK
Systems (http://www.peak-system.com). +
(..)
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o
This should be the module/driver name too.
Quoted 4 lines
Quoted 2 lines
+ +/* PEAK-System PCMCIA driver name */ +#define
DRV_NAME"peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.
Quoted 7 lines
Quoted 1 line
Yep -
peak_pcmciaWe just finished to talk about that and, as far as the PCAN-PC Card is a PC-CARD (16bit), we'd like to use the "
peak_pccard" text for the module/module file/source file names instead of "peak_pcmcia". Related
question: I suppose I'll have to change the "CONFIG_CAN_PEAK_PCMCIA" into "CONFIG_CAN_PEAK_PCCARD" too. Please confirm.
Hm. Not that good IMO ...
If you look into the Kernel config options there's a difference between PCCARD and PCMCIA:
linux/drivers/pcmcia/Kconfig says
---8<--- snip
if PCCARD
config PCMCIA
tristate "16-bit PCMCIA support"
select CRC32
default y
---help---
This option enables support for 16-bit PCMCIA cards. Most older PC-cards are such 16-bit PCMCIA cards, so unless you know you're only using 32-bit CardBus cards, say Y or M here.
To use 16-bit PCMCIA cards, you will need supporting software in most cases. (see the file <file:Documentation/Changes> for location and details).
To compile this driver as modules, choose M here: the module will be called pcmcia.
If unsure, say Y.
---8<--- snip
So your hardware is not a 32-bit Cardbus but a 16-bit PCMCIA card.
Putting the "PCAN-PC card" into the Kconfig description is fine but the driver source and kernel module should reflect the (16 bit) pcmcia driver state.
You may add to your Kconfig entry:
To compile this driver as module, choose M here: the module will be called peak_pcmcia.
Regards,
Oliver
Quoted 92 lines · Oliver Hartkopp
Quoted 8 lines · Grosjean Stephane
Quoted 5 lines
+config
CAN_PEAK_PCMCIA+ tristate "PEAK PCAN PC-CARD Card"tristate "PEAK PCAN PC-Card (PCMCIA)"
??
Please confirm: you'd like me to add the "(PCMCIA)" string at the end of the menu text, wouldn't you?
I read some more Kconfigs to check the current handling in other drivers.
I think
tristate "PEAK PCAN PC-Card"
is better - and reflects the PEAK adapter name (note the upper/lower case!). Although the
Kconfigentry is only visible when PCMCIA is enabled.Quoted 9 lines
Quoted 6 lines
Should we probably put all PCMCIA cards into a separate
linux/drivers/net/can/sja1000/pcmcia
directory - like we have it for the USB devices?
If my Humble Opinion may help you: not sure this will be lots of other pcmcia (can) adapters in the future...
ok. Forget it :-)
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ depends on PCMCIA + ---help--- + This driver is for the
PCAN PC-CARD PCMCIA card with 1 or 2 channels + from PEAK
Systems (http://www.peak-system.com). +(..)
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o
This should be the module/driver name too.
Quoted 4 lines
Quoted 2 lines
+ +/* PEAK-System PCMCIA driver name */ +#define
DRV_NAME"peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.Quoted 7 lines
Quoted 1 line
Yep -
peak_pcmciaWe just finished to talk about that and, as far as the PCAN-PC Card is a PC-CARD (16bit), we'd like to use the "
peak_pccard" text for the module/module file/source file names instead of "peak_pcmcia". Related
question: I suppose I'll have to change the "CONFIG_CAN_PEAK_PCMCIA" into "CONFIG_CAN_PEAK_PCCARD" too. Please confirm.Hm. Not that good IMO ...
If you look into the Kernel config options there's a difference between PCCARD and PCMCIA:
linux/drivers/pcmcia/Kconfig says
---8<--- snip
if PCCARD
config PCMCIA
tristate "16-bit PCMCIA support"
select CRC32
default y
---help---
This option enables support for 16-bit PCMCIA cards. Most older PC-cards are such 16-bit PCMCIA cards, so unless you know you're only using 32-bit CardBus cards, say Y or M here.To use 16-bit PCMCIA cards, you will need supporting software in most cases. (see the file <file:Documentation/Changes> for location and details).
To compile this driver as modules, choose M here: the module will be called pcmcia.
If unsure, say Y.
---8<--- snip
So your hardware is not a 32-bit Cardbus but a 16-bit PCMCIA card.
Quoted 7 lines
Putting the "PCAN-PC card" into the
Kconfigdescription is fine but the driver source and kernel module should reflect the (16 bit) pcmcia driver state.You may add to your
Kconfigentry:To compile this driver as module, choose M here: the module will be called
peak_pcmcia.
D'accord!
Wolfgang.
Hi Wolfgang,
Quoted 4 lines · Wolfgang Grandegger
Hi Stephane,
please send a patch using a proper subject line and commit message. Also add a CC to the pcmcia linux mailing list. Thanks.
Ok I'll do that for v2.
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ +/* PEAK-System PCMCIA driver name */ +#define DRV_NAME "peak_pccard"I find the mix of "
peak_pcmcia" and "peak_pccard" and "pcan_pccard" for the same hardware confusing. Please use just one name and prefix.
Ok, decision was made: peak_pcmcia, once for all!
Closed.
Quoted 4 lines
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ +/* PEAK-System PCMCIA driver version */ +#define DRV_VERSION_MAJOR 0 +#define DRV_VERSION_MINOR 2
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 45
Quoted 5 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+#define DRV_VERSION_SUBMINOR 0 + +#define DRV_VERSION_STRING __stringify(DRV_VERSION_MAJOR)"."\ + __stringify(DRV_VERSION_MINOR)"."\ + __stringify(DRV_VERSION_SUBMINOR)As for the USB driver, I would remove this redundant versioning stuff. Also version 0.2.0 does not really sound like like a stable piece of software.
Removed from both drivers.
Closed.
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +4
-0+ +#define DRV_CHAN_MAX 2 + +#define DRV_CAN_CLOCK (16000000 / 2)Hm, the prefix
DRV_here and below does not really make sense. But well, it's a minor issue.
PCC_
Closed.
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 262
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+static int pcan_write_eeprom (struct pcan_pccard *card,u16 addr,u8 v) +{ +u8 status; +int err, i; + +/* write instruction */ +pcan_write_reg (card,DRV_SPI_INR ,0x06 );Macro definitons would be nice.
TODO
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c line 269
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+/* wait until write enable */ +for (i =0 ; i<DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */ This comment does not tell me anything.
Ok, what about these one?
/* write command reading the status register */
...
/* get the status register and check write enable bit */
then;
/* write command reading the status register */
...
/* get the status register and check write in progress bit */
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +5
-0+ +write_eeprom_err: +dev_info (&card->dev->dev, +"writing 0x%x in eeprom @0x%x failed (err %d)\n" , + v, addr, err);Info or error. Can this happen? If yes, how often?
It's an error and I never saw it. Moreover, writing in eeprom is (only) done to power up/down the can connectors (so first when driver is loaded, second when it is unloaded). Moved the dev_info() into dev_err().
Quoted 9 lines
drivers/net/can/sja1000/peak_pcmcia.c line 327
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+return err; +} + +/* +* control the leds +* @led_mask: should be an or made of DRV_LED(x) +* @state: DRV_LED_ON, DRV_LED_OFF, DRV_LED_SLOW or DRV_LED_FAST +*/ Please remove the docbook tags.
Ok.
Quoted 21 lines
Quoted 21 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +21
-0+/* +* interrupt service routine +*/ +static irqreturn_t pcan_isr (int irq,void *dev_id) +{ +struct pcan_pccard *card = dev_id; +struct net_device *netdev; +irqreturn_t retval =IRQ_NONE ; +int i, again; + + do { + again = 0; + + /* Check interrupt for each channel */ + for (i = 0; i< card->chan_count; i++) { + netdev = card->channel[i].netdev; + if (!netdev) + continue; + + if (sja1000_interrupt(irq, netdev) == IRQ_HANDLED) + again = 1;
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 426
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+ } + +/* At least one channel handled the interrupt */ +if (again) + retval =IRQ_HANDLED ; + + }while (again);I wonder if it makes sense to limit the loop count.
Had a look to sja1000_interrupt(): you're right, could enter in an infinite loop if one of the sja1000 failed into always sending interrupt signals... On my side, I wonder why entering such a do { } while (again) loop?
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 602
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+ +dev_info (&dev->dev,"new PEAK-System pcmcia card detected:\n" ); + +dev_info (&dev->dev,"%s %s\n" , + dev->prod_id[0 ] ? dev->prod_id[0 ] :"PEAK-System" , + dev->prod_id[1 ] ? dev->prod_id[1 ] :"PCAN-PC Card" );One line (
dev_info) should be enough. Also "dev->dev" is not really readable. "dev->p[cmcia_]dev" would be much better.
Since this is the 2nd time this request comes, considering its priority as increased: thus, changed into a single dev_info(); dev changed into pdev: Ok.
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c line 625
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ card =kzalloc (sizeof (struct pcan_pccard ),GFP_KERNEL ); +if (!card) { +dev_err (&dev->dev,"kzalloc() failure\n" );Please be more specific, e.g.: "couldn't allocated card memory".
As you want, you're (one of) the chief(s) ;-)
Closed.
Quoted 40 lines
Quoted 40 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +40
-0+ +/* sja1000 api uses iomem */ + card->ioport_addr =ioport_map (dev->resource[0 ]->start, +resource_size (dev->resource[0 ])); +if (!card->ioport_addr) { + err = -ENOMEM ; + goto probe_err_3; + } + +/* display firware version */ +dev_info (&dev->dev,"firmware %d.%d\n" , +pcan_read_reg (card,DRV_FW_MAJOR ), +pcan_read_reg (card,DRV_FW_MINOR )); + +/* detect available channels */ +pcan_add_channels (card); +if (!card->chan_count) + goto probe_err_3; + +/* init the timer which controls the leds */ +init_timer (&card->led_timer); + card->led_timer.function = pcan_led_timer; + card->led_timer.data = (unsigned long )card; + +/* request the given irq */ + err =request_irq (dev->irq,&pcan_isr,IRQF_SHARED ,DRV_NAME , card); +if (err) + goto probe_err_4; + +/* power on the connectors */ +pcan_set_can_power (card,1 ); + +return 0 ; + +probe_err_4: +/* unregister can devices from network */ +pcan_free_channels (card); + +probe_err_3: +kfree (card);
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 678
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+ dev->priv =NULL ; + +probe_err_2: +pcmcia_disable_device (dev); + +probe_err_1: +return err;I'm missing
ioport_unmap()!
Yes you're perfectly right: in many cases, it will be right called by pcan_free_channels() but not before going to "probe_err_3", when no channel are detected. So changed code above into:
/* detect available channels */
pcan_add_channels(card);
if (!card->chan_count) {
ioport_unmap(card->ioport_addr);
goto probe_err_3;
}Quoted 3 lines
Thanks for your contribution.
Wolfgang.
You're welcome, thanks for your time.
Stéphane
Hi Stephane,
Quoted 13 lines · Grosjean Stephane
Hi Wolfgang,
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c line 269
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+/* wait until write enable */ +for (i =0 ; i<DRV_WRITE_MAX_LOOP ; i++) { +/* RDSR */ This comment does not tell me anything.
Ok, what about these one?
/* write command reading the status register */
...
/* get the status register and check write enable bit */
Quoted 5 lines
then;
/* write command reading the status register */
...
/* get the status register and check write in progress bit */
I don't know what RDSR means, sorry. Just put something human readable. With some meaningful macro definitions the comment might even be obsolete/redundant.
..
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+/* +* interrupt service routine +*/ +static irqreturn_t pcan_isr (int irq,void *dev_id) +{ +struct pcan_pccard *card = dev_id; +struct net_device *netdev;
Quoted 8 lines
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c
Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +8
-0+irqreturn_t retval =IRQ_NONE ; +int i, again; + + do { + again = 0; + + /* Check interrupt for each channel */ + for (i = 0; i< card->chan_count; i++) {
s/i</i </
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +6
-0+ netdev = card->channel[i].netdev; +if (!netdev) +continue ; + +if (sja1000_interrupt (irq, netdev) ==IRQ_HANDLED ) + again =1 ;Quoted 8 lines
drivers/net/can/sja1000/peak_pcmcia.c line 426
Quoted 7 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +7
-0+ } + +/* At least one channel handled the interrupt */ +if (again) + retval =IRQ_HANDLED ; + + }while (again);I wonder if it makes sense to limit the loop count.
Quoted 4 lines
Had a look to
sja1000_interrupt(): you're right, could enter in an infinite loop if one of the sja1000 failed into always sending interrupt signals...
On my side, I wonder why entering such a do { } while (again) loop?
Is it an edge or level sensitive interrupt? This custom interrupt handling was introduced to handle hardware which does not allow to handle the interrupt per device and the loop is required to avoid interrupt losses, IIRC. The corresponding PEAK PCAN driver has a similar for loop:
loop_count = 0; // restart, since all channels must respond in
one pass with no interrupt pending
Quoted 7 lines
Quoted 4 lines
drivers/net/can/sja1000/peak_pcmcia.c line 625
Quoted 3 lines
drivers/net/can/sja1000/peak_pcmcia.c new file +3
-0+ card =kzalloc (sizeof (struct pcan_pccard ),GFP_KERNEL ); +if (!card) { +dev_err (&dev->dev,"kzalloc() failure\n" );Please be more specific, e.g.: "couldn't allocated card memory".
As you want, you're (one of) the chief(s) ;-)
Closed.
Well, the messages should make sense for the user of that driver, and not for the developer.
Wolfgang