Skip to content

Commit 98a20b7

Browse files
committed
Merge tag 'linux-can-next-for-3.16-20140425' of git://gitorious.org/linux-can/linux-can-next
Marc Kleine-Budde says: ==================== this is a pull request of 10 patches for net-next/master. It consists of three patches by Alexander Shiyan, which improve the mcp251x driver. Stefano Babic's patch move the SPI driver into a sub folder. The three patches by Olivier Sobrie add support for the Kvaser Leaf v2 and usb mini PCIe hardware to the existing driver. Alexander Stein contributes eg20t support to the c_can pci driver. Together with the patches on the net-tree, we'll be able to remove the pch_can driver soon. Kurt Van Dijck's two patches clean up the sysfs attributes of the softing driver. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 16b4630 + 0f8dced commit 98a20b7

File tree

9 files changed

+154
-95
lines changed

9 files changed

+154
-95
lines changed

drivers/net/can/Kconfig

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ config CAN_TI_HECC
7777
Driver for TI HECC (High End CAN Controller) module found on many
7878
TI devices. The device specifications are available from www.ti.com
7979

80-
config CAN_MCP251X
81-
tristate "Microchip MCP251x SPI CAN controllers"
82-
depends on SPI && HAS_DMA
83-
---help---
84-
Driver for the Microchip MCP251x SPI CAN controllers.
85-
8680
config CAN_BFIN
8781
depends on BF534 || BF536 || BF537 || BF538 || BF539 || BF54x
8882
tristate "Analog Devices Blackfin on-chip CAN"
@@ -133,6 +127,8 @@ source "drivers/net/can/c_can/Kconfig"
133127

134128
source "drivers/net/can/cc770/Kconfig"
135129

130+
source "drivers/net/can/spi/Kconfig"
131+
136132
source "drivers/net/can/usb/Kconfig"
137133

138134
source "drivers/net/can/softing/Kconfig"

drivers/net/can/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ can-dev-y := dev.o
1010

1111
can-dev-$(CONFIG_CAN_LEDS) += led.o
1212

13+
obj-y += spi/
1314
obj-y += usb/
1415
obj-y += softing/
1516

@@ -19,7 +20,6 @@ obj-$(CONFIG_CAN_C_CAN) += c_can/
1920
obj-$(CONFIG_CAN_CC770) += cc770/
2021
obj-$(CONFIG_CAN_AT91) += at91_can.o
2122
obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
22-
obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
2323
obj-$(CONFIG_CAN_BFIN) += bfin_can.o
2424
obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
2525
obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o

drivers/net/can/c_can/c_can_pci.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
#include "c_can.h"
2121

22+
#define PCI_DEVICE_ID_PCH_CAN 0x8818
23+
#define PCH_PCI_SOFT_RESET 0x01fc
24+
2225
enum c_can_pci_reg_align {
2326
C_CAN_REG_ALIGN_16,
2427
C_CAN_REG_ALIGN_32,
28+
C_CAN_REG_32,
2529
};
2630

2731
struct c_can_pci_data {
@@ -31,6 +35,10 @@ struct c_can_pci_data {
3135
enum c_can_pci_reg_align reg_align;
3236
/* Set the frequency */
3337
unsigned int freq;
38+
/* PCI bar number */
39+
int bar;
40+
/* Callback for reset */
41+
void (*init)(const struct c_can_priv *priv, bool enable);
3442
};
3543

3644
/*
@@ -63,6 +71,29 @@ static void c_can_pci_write_reg_aligned_to_32bit(struct c_can_priv *priv,
6371
writew(val, priv->base + 2 * priv->regs[index]);
6472
}
6573

74+
static u16 c_can_pci_read_reg_32bit(struct c_can_priv *priv,
75+
enum reg index)
76+
{
77+
return (u16)ioread32(priv->base + 2 * priv->regs[index]);
78+
}
79+
80+
static void c_can_pci_write_reg_32bit(struct c_can_priv *priv,
81+
enum reg index, u16 val)
82+
{
83+
iowrite32((u32)val, priv->base + 2 * priv->regs[index]);
84+
}
85+
86+
static void c_can_pci_reset_pch(const struct c_can_priv *priv, bool enable)
87+
{
88+
if (enable) {
89+
u32 __iomem *addr = priv->base + PCH_PCI_SOFT_RESET;
90+
91+
/* write to sw reset register */
92+
iowrite32(1, addr);
93+
iowrite32(0, addr);
94+
}
95+
}
96+
6697
static int c_can_pci_probe(struct pci_dev *pdev,
6798
const struct pci_device_id *ent)
6899
{
@@ -87,7 +118,8 @@ static int c_can_pci_probe(struct pci_dev *pdev,
87118
pci_set_master(pdev);
88119
pci_enable_msi(pdev);
89120

90-
addr = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
121+
addr = pci_iomap(pdev, c_can_pci_data->bar,
122+
pci_resource_len(pdev, c_can_pci_data->bar));
91123
if (!addr) {
92124
dev_err(&pdev->dev,
93125
"device has no PCI memory resources, "
@@ -142,11 +174,17 @@ static int c_can_pci_probe(struct pci_dev *pdev,
142174
priv->read_reg = c_can_pci_read_reg_aligned_to_16bit;
143175
priv->write_reg = c_can_pci_write_reg_aligned_to_16bit;
144176
break;
177+
case C_CAN_REG_32:
178+
priv->read_reg = c_can_pci_read_reg_32bit;
179+
priv->write_reg = c_can_pci_write_reg_32bit;
180+
break;
145181
default:
146182
ret = -EINVAL;
147183
goto out_free_c_can;
148184
}
149185

186+
priv->raminit = c_can_pci_data->init;
187+
150188
ret = register_c_can_dev(dev);
151189
if (ret) {
152190
dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
@@ -193,6 +231,15 @@ static struct c_can_pci_data c_can_sta2x11= {
193231
.type = BOSCH_C_CAN,
194232
.reg_align = C_CAN_REG_ALIGN_32,
195233
.freq = 52000000, /* 52 Mhz */
234+
.bar = 0,
235+
};
236+
237+
static struct c_can_pci_data c_can_pch = {
238+
.type = BOSCH_C_CAN,
239+
.reg_align = C_CAN_REG_32,
240+
.freq = 50000000, /* 50 MHz */
241+
.init = c_can_pci_reset_pch,
242+
.bar = 1,
196243
};
197244

198245
#define C_CAN_ID(_vend, _dev, _driverdata) { \
@@ -202,6 +249,8 @@ static struct c_can_pci_data c_can_sta2x11= {
202249
static DEFINE_PCI_DEVICE_TABLE(c_can_pci_tbl) = {
203250
C_CAN_ID(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_CAN,
204251
c_can_sta2x11),
252+
C_CAN_ID(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH_CAN,
253+
c_can_pch),
205254
{},
206255
};
207256
static struct pci_driver c_can_pci_driver = {

drivers/net/can/softing/softing_main.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,6 @@ static int softing_card_boot(struct softing *card)
556556
/*
557557
* netdev sysfs
558558
*/
559-
static ssize_t show_channel(struct device *dev, struct device_attribute *attr,
560-
char *buf)
561-
{
562-
struct net_device *ndev = to_net_dev(dev);
563-
struct softing_priv *priv = netdev2softing(ndev);
564-
565-
return sprintf(buf, "%i\n", priv->index);
566-
}
567-
568559
static ssize_t show_chip(struct device *dev, struct device_attribute *attr,
569560
char *buf)
570561
{
@@ -609,12 +600,10 @@ static ssize_t store_output(struct device *dev, struct device_attribute *attr,
609600
return count;
610601
}
611602

612-
static const DEVICE_ATTR(channel, S_IRUGO, show_channel, NULL);
613603
static const DEVICE_ATTR(chip, S_IRUGO, show_chip, NULL);
614604
static const DEVICE_ATTR(output, S_IRUGO | S_IWUSR, show_output, store_output);
615605

616606
static const struct attribute *const netdev_sysfs_attrs[] = {
617-
&dev_attr_channel.attr,
618607
&dev_attr_chip.attr,
619608
&dev_attr_output.attr,
620609
NULL,
@@ -679,17 +668,20 @@ static int softing_netdev_register(struct net_device *netdev)
679668
{
680669
int ret;
681670

682-
netdev->sysfs_groups[0] = &netdev_sysfs_group;
683671
ret = register_candev(netdev);
684672
if (ret) {
685673
dev_alert(&netdev->dev, "register failed\n");
686674
return ret;
687675
}
676+
if (sysfs_create_group(&netdev->dev.kobj, &netdev_sysfs_group) < 0)
677+
netdev_alert(netdev, "sysfs group failed\n");
678+
688679
return 0;
689680
}
690681

691682
static void softing_netdev_cleanup(struct net_device *netdev)
692683
{
684+
sysfs_remove_group(&netdev->dev.kobj, &netdev_sysfs_group);
693685
unregister_candev(netdev);
694686
free_candev(netdev);
695687
}
@@ -721,8 +713,6 @@ DEV_ATTR_RO(firmware_version, id.fw_version);
721713
DEV_ATTR_RO_STR(hardware, pdat->name);
722714
DEV_ATTR_RO(hardware_version, id.hw_version);
723715
DEV_ATTR_RO(license, id.license);
724-
DEV_ATTR_RO(frequency, id.freq);
725-
DEV_ATTR_RO(txpending, tx.pending);
726716

727717
static struct attribute *softing_pdev_attrs[] = {
728718
&dev_attr_serial.attr,
@@ -731,8 +721,6 @@ static struct attribute *softing_pdev_attrs[] = {
731721
&dev_attr_hardware.attr,
732722
&dev_attr_hardware_version.attr,
733723
&dev_attr_license.attr,
734-
&dev_attr_frequency.attr,
735-
&dev_attr_txpending.attr,
736724
NULL,
737725
};
738726

drivers/net/can/spi/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
menu "CAN SPI interfaces"
2+
depends on SPI
3+
4+
config CAN_MCP251X
5+
tristate "Microchip MCP251x SPI CAN controllers"
6+
depends on HAS_DMA
7+
---help---
8+
Driver for the Microchip MCP251x SPI CAN controllers.
9+
10+
endmenu

drivers/net/can/spi/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Makefile for the Linux Controller Area Network SPI drivers.
3+
#
4+
5+
6+
obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
7+
8+
ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG

drivers/net/can/mcp251x.c renamed to drivers/net/can/spi/mcp251x.c

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@
214214

215215
#define TX_ECHO_SKB_MAX 1
216216

217+
#define MCP251X_OST_DELAY_MS (5)
218+
217219
#define DEVICE_NAME "mcp251x"
218220

219221
static int mcp251x_enable_dma; /* Enable SPI DMA. Default: 0 (Off) */
@@ -624,50 +626,45 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
624626
static int mcp251x_hw_reset(struct spi_device *spi)
625627
{
626628
struct mcp251x_priv *priv = spi_get_drvdata(spi);
629+
u8 reg;
627630
int ret;
628-
unsigned long timeout;
631+
632+
/* Wait for oscillator startup timer after power up */
633+
mdelay(MCP251X_OST_DELAY_MS);
629634

630635
priv->spi_tx_buf[0] = INSTRUCTION_RESET;
631-
ret = spi_write(spi, priv->spi_tx_buf, 1);
632-
if (ret) {
633-
dev_err(&spi->dev, "reset failed: ret = %d\n", ret);
634-
return -EIO;
635-
}
636+
ret = mcp251x_spi_trans(spi, 1);
637+
if (ret)
638+
return ret;
639+
640+
/* Wait for oscillator startup timer after reset */
641+
mdelay(MCP251X_OST_DELAY_MS);
642+
643+
reg = mcp251x_read_reg(spi, CANSTAT);
644+
if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
645+
return -ENODEV;
636646

637-
/* Wait for reset to finish */
638-
timeout = jiffies + HZ;
639-
mdelay(10);
640-
while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK)
641-
!= CANCTRL_REQOP_CONF) {
642-
schedule();
643-
if (time_after(jiffies, timeout)) {
644-
dev_err(&spi->dev, "MCP251x didn't"
645-
" enter in conf mode after reset\n");
646-
return -EBUSY;
647-
}
648-
}
649647
return 0;
650648
}
651649

652650
static int mcp251x_hw_probe(struct spi_device *spi)
653651
{
654-
int st1, st2;
652+
u8 ctrl;
653+
int ret;
655654

656-
mcp251x_hw_reset(spi);
655+
ret = mcp251x_hw_reset(spi);
656+
if (ret)
657+
return ret;
657658

658-
/*
659-
* Please note that these are "magic values" based on after
660-
* reset defaults taken from data sheet which allows us to see
661-
* if we really have a chip on the bus (we avoid common all
662-
* zeroes or all ones situations)
663-
*/
664-
st1 = mcp251x_read_reg(spi, CANSTAT) & 0xEE;
665-
st2 = mcp251x_read_reg(spi, CANCTRL) & 0x17;
659+
ctrl = mcp251x_read_reg(spi, CANCTRL);
660+
661+
dev_dbg(&spi->dev, "CANCTRL 0x%02x\n", ctrl);
666662

667-
dev_dbg(&spi->dev, "CANSTAT 0x%02x CANCTRL 0x%02x\n", st1, st2);
663+
/* Check for power up default value */
664+
if ((ctrl & 0x17) != 0x07)
665+
return -ENODEV;
668666

669-
/* Check for power up default values */
670-
return (st1 == 0x80 && st2 == 0x07) ? 1 : 0;
667+
return 0;
671668
}
672669

673670
static int mcp251x_power_enable(struct regulator *reg, int enable)
@@ -776,7 +773,6 @@ static void mcp251x_restart_work_handler(struct work_struct *ws)
776773

777774
mutex_lock(&priv->mcp_lock);
778775
if (priv->after_suspend) {
779-
mdelay(10);
780776
mcp251x_hw_reset(spi);
781777
mcp251x_setup(net, priv, spi);
782778
if (priv->after_suspend & AFTER_SUSPEND_RESTART) {
@@ -1032,8 +1028,8 @@ static int mcp251x_can_probe(struct spi_device *spi)
10321028
struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev);
10331029
struct net_device *net;
10341030
struct mcp251x_priv *priv;
1035-
int freq, ret = -ENODEV;
10361031
struct clk *clk;
1032+
int freq, ret;
10371033

10381034
clk = devm_clk_get(&spi->dev, NULL);
10391035
if (IS_ERR(clk)) {
@@ -1076,6 +1072,18 @@ static int mcp251x_can_probe(struct spi_device *spi)
10761072
priv->net = net;
10771073
priv->clk = clk;
10781074

1075+
spi_set_drvdata(spi, priv);
1076+
1077+
/* Configure the SPI bus */
1078+
spi->bits_per_word = 8;
1079+
if (mcp251x_is_2510(spi))
1080+
spi->max_speed_hz = spi->max_speed_hz ? : 5 * 1000 * 1000;
1081+
else
1082+
spi->max_speed_hz = spi->max_speed_hz ? : 10 * 1000 * 1000;
1083+
ret = spi_setup(spi);
1084+
if (ret)
1085+
goto out_clk;
1086+
10791087
priv->power = devm_regulator_get(&spi->dev, "vdd");
10801088
priv->transceiver = devm_regulator_get(&spi->dev, "xceiver");
10811089
if ((PTR_ERR(priv->power) == -EPROBE_DEFER) ||
@@ -1088,8 +1096,6 @@ static int mcp251x_can_probe(struct spi_device *spi)
10881096
if (ret)
10891097
goto out_clk;
10901098

1091-
spi_set_drvdata(spi, priv);
1092-
10931099
priv->spi = spi;
10941100
mutex_init(&priv->mcp_lock);
10951101

@@ -1134,20 +1140,11 @@ static int mcp251x_can_probe(struct spi_device *spi)
11341140

11351141
SET_NETDEV_DEV(net, &spi->dev);
11361142

1137-
/* Configure the SPI bus */
1138-
spi->mode = spi->mode ? : SPI_MODE_0;
1139-
if (mcp251x_is_2510(spi))
1140-
spi->max_speed_hz = spi->max_speed_hz ? : 5 * 1000 * 1000;
1141-
else
1142-
spi->max_speed_hz = spi->max_speed_hz ? : 10 * 1000 * 1000;
1143-
spi->bits_per_word = 8;
1144-
spi_setup(spi);
1145-
11461143
/* Here is OK to not lock the MCP, no one knows about it yet */
1147-
if (!mcp251x_hw_probe(spi)) {
1148-
ret = -ENODEV;
1144+
ret = mcp251x_hw_probe(spi);
1145+
if (ret)
11491146
goto error_probe;
1150-
}
1147+
11511148
mcp251x_hw_sleep(spi);
11521149

11531150
ret = register_candev(net);
@@ -1156,7 +1153,7 @@ static int mcp251x_can_probe(struct spi_device *spi)
11561153

11571154
devm_can_led_init(net);
11581155

1159-
return ret;
1156+
return 0;
11601157

11611158
error_probe:
11621159
if (mcp251x_enable_dma)

0 commit comments

Comments
 (0)