plx_pci.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * Copyright (C) 2008-2010 Pavel Cheblakov <P.B.Cheblakov@inp.nsk.su>
  3. *
  4. * Derived from the ems_pci.c driver:
  5. * Copyright (C) 2007 Wolfgang Grandegger <wg@grandegger.com>
  6. * Copyright (C) 2008 Markus Plessing <plessing@ems-wuensche.com>
  7. * Copyright (C) 2008 Sebastian Haas <haas@ems-wuensche.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the version 2 of the GNU General Public License
  11. * as published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/pci.h>
  29. #include <linux/can/dev.h>
  30. #include <linux/io.h>
  31. #include "sja1000.h"
  32. #define DRV_NAME "sja1000_plx_pci"
  33. MODULE_AUTHOR("Pavel Cheblakov <P.B.Cheblakov@inp.nsk.su>");
  34. MODULE_DESCRIPTION("Socket-CAN driver for PLX90xx PCI-bridge cards with "
  35. "the SJA1000 chips");
  36. MODULE_SUPPORTED_DEVICE("Adlink PCI-7841/cPCI-7841, "
  37. "Adlink PCI-7841/cPCI-7841 SE, "
  38. "Marathon CAN-bus-PCI, "
  39. "TEWS TECHNOLOGIES TPMC810, "
  40. "esd CAN-PCI/CPCI/PCI104/200, "
  41. "esd CAN-PCI/PMC/266, "
  42. "esd CAN-PCIe/2000")
  43. MODULE_LICENSE("GPL v2");
  44. #define PLX_PCI_MAX_CHAN 2
  45. struct plx_pci_card {
  46. int channels; /* detected channels count */
  47. struct net_device *net_dev[PLX_PCI_MAX_CHAN];
  48. void __iomem *conf_addr;
  49. /* Pointer to device-dependent reset function */
  50. void (*reset_func)(struct pci_dev *pdev);
  51. };
  52. #define PLX_PCI_CAN_CLOCK (16000000 / 2)
  53. /* PLX9030/9050/9052 registers */
  54. #define PLX_INTCSR 0x4c /* Interrupt Control/Status */
  55. #define PLX_CNTRL 0x50 /* User I/O, Direct Slave Response,
  56. * Serial EEPROM, and Initialization
  57. * Control register
  58. */
  59. #define PLX_LINT1_EN 0x1 /* Local interrupt 1 enable */
  60. #define PLX_LINT2_EN (1 << 3) /* Local interrupt 2 enable */
  61. #define PLX_PCI_INT_EN (1 << 6) /* PCI Interrupt Enable */
  62. #define PLX_PCI_RESET (1 << 30) /* PCI Adapter Software Reset */
  63. /* PLX9056 registers */
  64. #define PLX9056_INTCSR 0x68 /* Interrupt Control/Status */
  65. #define PLX9056_CNTRL 0x6c /* Control / Software Reset */
  66. #define PLX9056_LINTI (1 << 11)
  67. #define PLX9056_PCI_INT_EN (1 << 8)
  68. #define PLX9056_PCI_RCR (1 << 29) /* Read Configuration Registers */
  69. /*
  70. * The board configuration is probably following:
  71. * RX1 is connected to ground.
  72. * TX1 is not connected.
  73. * CLKO is not connected.
  74. * Setting the OCR register to 0xDA is a good idea.
  75. * This means normal output mode, push-pull and the correct polarity.
  76. */
  77. #define PLX_PCI_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
  78. /*
  79. * In the CDR register, you should set CBP to 1.
  80. * You will probably also want to set the clock divider value to 7
  81. * (meaning direct oscillator output) because the second SJA1000 chip
  82. * is driven by the first one CLKOUT output.
  83. */
  84. #define PLX_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK)
  85. /* SJA1000 Control Register in the BasicCAN Mode */
  86. #define REG_CR 0x00
  87. /* States of some SJA1000 registers after hardware reset in the BasicCAN mode*/
  88. #define REG_CR_BASICCAN_INITIAL 0x21
  89. #define REG_CR_BASICCAN_INITIAL_MASK 0xa1
  90. #define REG_SR_BASICCAN_INITIAL 0x0c
  91. #define REG_IR_BASICCAN_INITIAL 0xe0
  92. /* States of some SJA1000 registers after hardware reset in the PeliCAN mode*/
  93. #define REG_MOD_PELICAN_INITIAL 0x01
  94. #define REG_SR_PELICAN_INITIAL 0x3c
  95. #define REG_IR_PELICAN_INITIAL 0x00
  96. #define ADLINK_PCI_VENDOR_ID 0x144A
  97. #define ADLINK_PCI_DEVICE_ID 0x7841
  98. #define ESD_PCI_SUB_SYS_ID_PCI200 0x0004
  99. #define ESD_PCI_SUB_SYS_ID_PCI266 0x0009
  100. #define ESD_PCI_SUB_SYS_ID_PMC266 0x000e
  101. #define ESD_PCI_SUB_SYS_ID_CPCI200 0x010b
  102. #define ESD_PCI_SUB_SYS_ID_PCIE2000 0x0200
  103. #define ESD_PCI_SUB_SYS_ID_PCI104200 0x0501
  104. #define MARATHON_PCI_DEVICE_ID 0x2715
  105. #define TEWS_PCI_VENDOR_ID 0x1498
  106. #define TEWS_PCI_DEVICE_ID_TMPC810 0x032A
  107. static void plx_pci_reset_common(struct pci_dev *pdev);
  108. static void plx_pci_reset_marathon(struct pci_dev *pdev);
  109. static void plx9056_pci_reset_common(struct pci_dev *pdev);
  110. struct plx_pci_channel_map {
  111. u32 bar;
  112. u32 offset;
  113. u32 size; /* 0x00 - auto, e.g. length of entire bar */
  114. };
  115. struct plx_pci_card_info {
  116. const char *name;
  117. int channel_count;
  118. u32 can_clock;
  119. u8 ocr; /* output control register */
  120. u8 cdr; /* clock divider register */
  121. /* Parameters for mapping local configuration space */
  122. struct plx_pci_channel_map conf_map;
  123. /* Parameters for mapping the SJA1000 chips */
  124. struct plx_pci_channel_map chan_map_tbl[PLX_PCI_MAX_CHAN];
  125. /* Pointer to device-dependent reset function */
  126. void (*reset_func)(struct pci_dev *pdev);
  127. };
  128. static struct plx_pci_card_info plx_pci_card_info_adlink __devinitdata = {
  129. "Adlink PCI-7841/cPCI-7841", 2,
  130. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  131. {1, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
  132. &plx_pci_reset_common
  133. /* based on PLX9052 */
  134. };
  135. static struct plx_pci_card_info plx_pci_card_info_adlink_se __devinitdata = {
  136. "Adlink PCI-7841/cPCI-7841 SE", 2,
  137. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  138. {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
  139. &plx_pci_reset_common
  140. /* based on PLX9052 */
  141. };
  142. static struct plx_pci_card_info plx_pci_card_info_esd200 __devinitdata = {
  143. "esd CAN-PCI/CPCI/PCI104/200", 2,
  144. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  145. {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
  146. &plx_pci_reset_common
  147. /* based on PLX9030/9050 */
  148. };
  149. static struct plx_pci_card_info plx_pci_card_info_esd266 __devinitdata = {
  150. "esd CAN-PCI/PMC/266", 2,
  151. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  152. {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
  153. &plx9056_pci_reset_common
  154. /* based on PLX9056 */
  155. };
  156. static struct plx_pci_card_info plx_pci_card_info_esd2000 __devinitdata = {
  157. "esd CAN-PCIe/2000", 2,
  158. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  159. {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
  160. &plx9056_pci_reset_common
  161. /* based on PEX8311 */
  162. };
  163. static struct plx_pci_card_info plx_pci_card_info_marathon __devinitdata = {
  164. "Marathon CAN-bus-PCI", 2,
  165. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  166. {0, 0x00, 0x00}, { {2, 0x00, 0x00}, {4, 0x00, 0x00} },
  167. &plx_pci_reset_marathon
  168. /* based on PLX9052 */
  169. };
  170. static struct plx_pci_card_info plx_pci_card_info_tews __devinitdata = {
  171. "TEWS TECHNOLOGIES TPMC810", 2,
  172. PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
  173. {0, 0x00, 0x00}, { {2, 0x000, 0x80}, {2, 0x100, 0x80} },
  174. &plx_pci_reset_common
  175. /* based on PLX9030 */
  176. };
  177. static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = {
  178. {
  179. /* Adlink PCI-7841/cPCI-7841 */
  180. ADLINK_PCI_VENDOR_ID, ADLINK_PCI_DEVICE_ID,
  181. PCI_ANY_ID, PCI_ANY_ID,
  182. PCI_CLASS_NETWORK_OTHER << 8, ~0,
  183. (kernel_ulong_t)&plx_pci_card_info_adlink
  184. },
  185. {
  186. /* Adlink PCI-7841/cPCI-7841 SE */
  187. ADLINK_PCI_VENDOR_ID, ADLINK_PCI_DEVICE_ID,
  188. PCI_ANY_ID, PCI_ANY_ID,
  189. PCI_CLASS_COMMUNICATION_OTHER << 8, ~0,
  190. (kernel_ulong_t)&plx_pci_card_info_adlink_se
  191. },
  192. {
  193. /* esd CAN-PCI/200 */
  194. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
  195. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_PCI200,
  196. 0, 0,
  197. (kernel_ulong_t)&plx_pci_card_info_esd200
  198. },
  199. {
  200. /* esd CAN-CPCI/200 */
  201. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
  202. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_CPCI200,
  203. 0, 0,
  204. (kernel_ulong_t)&plx_pci_card_info_esd200
  205. },
  206. {
  207. /* esd CAN-PCI104/200 */
  208. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
  209. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_PCI104200,
  210. 0, 0,
  211. (kernel_ulong_t)&plx_pci_card_info_esd200
  212. },
  213. {
  214. /* esd CAN-PCI/266 */
  215. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9056,
  216. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_PCI266,
  217. 0, 0,
  218. (kernel_ulong_t)&plx_pci_card_info_esd266
  219. },
  220. {
  221. /* esd CAN-PMC/266 */
  222. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9056,
  223. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_PMC266,
  224. 0, 0,
  225. (kernel_ulong_t)&plx_pci_card_info_esd266
  226. },
  227. {
  228. /* esd CAN-PCIE/2000 */
  229. PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9056,
  230. PCI_VENDOR_ID_ESDGMBH, ESD_PCI_SUB_SYS_ID_PCIE2000,
  231. 0, 0,
  232. (kernel_ulong_t)&plx_pci_card_info_esd2000
  233. },
  234. {
  235. /* Marathon CAN-bus-PCI card */
  236. PCI_VENDOR_ID_PLX, MARATHON_PCI_DEVICE_ID,
  237. PCI_ANY_ID, PCI_ANY_ID,
  238. 0, 0,
  239. (kernel_ulong_t)&plx_pci_card_info_marathon
  240. },
  241. {
  242. /* TEWS TECHNOLOGIES TPMC810 card */
  243. TEWS_PCI_VENDOR_ID, TEWS_PCI_DEVICE_ID_TMPC810,
  244. PCI_ANY_ID, PCI_ANY_ID,
  245. 0, 0,
  246. (kernel_ulong_t)&plx_pci_card_info_tews
  247. },
  248. { 0,}
  249. };
  250. MODULE_DEVICE_TABLE(pci, plx_pci_tbl);
  251. static u8 plx_pci_read_reg(const struct sja1000_priv *priv, int port)
  252. {
  253. return ioread8(priv->reg_base + port);
  254. }
  255. static void plx_pci_write_reg(const struct sja1000_priv *priv, int port, u8 val)
  256. {
  257. iowrite8(val, priv->reg_base + port);
  258. }
  259. /*
  260. * Check if a CAN controller is present at the specified location
  261. * by trying to switch 'em from the Basic mode into the PeliCAN mode.
  262. * Also check states of some registers in reset mode.
  263. */
  264. static inline int plx_pci_check_sja1000(const struct sja1000_priv *priv)
  265. {
  266. int flag = 0;
  267. /*
  268. * Check registers after hardware reset (the Basic mode)
  269. * See states on p. 10 of the Datasheet.
  270. */
  271. if ((priv->read_reg(priv, REG_CR) & REG_CR_BASICCAN_INITIAL_MASK) ==
  272. REG_CR_BASICCAN_INITIAL &&
  273. (priv->read_reg(priv, REG_SR) == REG_SR_BASICCAN_INITIAL) &&
  274. (priv->read_reg(priv, REG_IR) == REG_IR_BASICCAN_INITIAL))
  275. flag = 1;
  276. /* Bring the SJA1000 into the PeliCAN mode*/
  277. priv->write_reg(priv, REG_CDR, CDR_PELICAN);
  278. /*
  279. * Check registers after reset in the PeliCAN mode.
  280. * See states on p. 23 of the Datasheet.
  281. */
  282. if (priv->read_reg(priv, REG_MOD) == REG_MOD_PELICAN_INITIAL &&
  283. priv->read_reg(priv, REG_SR) == REG_SR_PELICAN_INITIAL &&
  284. priv->read_reg(priv, REG_IR) == REG_IR_PELICAN_INITIAL)
  285. return flag;
  286. return 0;
  287. }
  288. /*
  289. * PLX9030/50/52 software reset
  290. * Also LRESET# asserts and brings to reset device on the Local Bus (if wired).
  291. * For most cards it's enough for reset the SJA1000 chips.
  292. */
  293. static void plx_pci_reset_common(struct pci_dev *pdev)
  294. {
  295. struct plx_pci_card *card = pci_get_drvdata(pdev);
  296. u32 cntrl;
  297. cntrl = ioread32(card->conf_addr + PLX_CNTRL);
  298. cntrl |= PLX_PCI_RESET;
  299. iowrite32(cntrl, card->conf_addr + PLX_CNTRL);
  300. udelay(100);
  301. cntrl ^= PLX_PCI_RESET;
  302. iowrite32(cntrl, card->conf_addr + PLX_CNTRL);
  303. };
  304. /*
  305. * PLX9056 software reset
  306. * Assert LRESET# and reset device(s) on the Local Bus (if wired).
  307. */
  308. static void plx9056_pci_reset_common(struct pci_dev *pdev)
  309. {
  310. struct plx_pci_card *card = pci_get_drvdata(pdev);
  311. u32 cntrl;
  312. /* issue a local bus reset */
  313. cntrl = ioread32(card->conf_addr + PLX9056_CNTRL);
  314. cntrl |= PLX_PCI_RESET;
  315. iowrite32(cntrl, card->conf_addr + PLX9056_CNTRL);
  316. udelay(100);
  317. cntrl ^= PLX_PCI_RESET;
  318. iowrite32(cntrl, card->conf_addr + PLX9056_CNTRL);
  319. /* reload local configuration from EEPROM */
  320. cntrl |= PLX9056_PCI_RCR;
  321. iowrite32(cntrl, card->conf_addr + PLX9056_CNTRL);
  322. /*
  323. * There is no safe way to poll for the end
  324. * of reconfiguration process. Waiting for 10ms
  325. * is safe.
  326. */
  327. mdelay(10);
  328. cntrl ^= PLX9056_PCI_RCR;
  329. iowrite32(cntrl, card->conf_addr + PLX9056_CNTRL);
  330. };
  331. /* Special reset function for Marathon card */
  332. static void plx_pci_reset_marathon(struct pci_dev *pdev)
  333. {
  334. void __iomem *reset_addr;
  335. int i;
  336. static const int reset_bar[2] = {3, 5};
  337. plx_pci_reset_common(pdev);
  338. for (i = 0; i < 2; i++) {
  339. reset_addr = pci_iomap(pdev, reset_bar[i], 0);
  340. if (!reset_addr) {
  341. dev_err(&pdev->dev, "Failed to remap reset "
  342. "space %d (BAR%d)\n", i, reset_bar[i]);
  343. } else {
  344. /* reset the SJA1000 chip */
  345. iowrite8(0x1, reset_addr);
  346. udelay(100);
  347. pci_iounmap(pdev, reset_addr);
  348. }
  349. }
  350. }
  351. static void plx_pci_del_card(struct pci_dev *pdev)
  352. {
  353. struct plx_pci_card *card = pci_get_drvdata(pdev);
  354. struct net_device *dev;
  355. struct sja1000_priv *priv;
  356. int i = 0;
  357. for (i = 0; i < card->channels; i++) {
  358. dev = card->net_dev[i];
  359. if (!dev)
  360. continue;
  361. dev_info(&pdev->dev, "Removing %s\n", dev->name);
  362. unregister_sja1000dev(dev);
  363. priv = netdev_priv(dev);
  364. if (priv->reg_base)
  365. pci_iounmap(pdev, priv->reg_base);
  366. free_sja1000dev(dev);
  367. }
  368. card->reset_func(pdev);
  369. /*
  370. * Disable interrupts from PCI-card and disable local
  371. * interrupts
  372. */
  373. if (pdev->device != PCI_DEVICE_ID_PLX_9056)
  374. iowrite32(0x0, card->conf_addr + PLX_INTCSR);
  375. else
  376. iowrite32(0x0, card->conf_addr + PLX9056_INTCSR);
  377. if (card->conf_addr)
  378. pci_iounmap(pdev, card->conf_addr);
  379. kfree(card);
  380. pci_disable_device(pdev);
  381. pci_set_drvdata(pdev, NULL);
  382. }
  383. /*
  384. * Probe PLX90xx based device for the SJA1000 chips and register each
  385. * available CAN channel to SJA1000 Socket-CAN subsystem.
  386. */
  387. static int __devinit plx_pci_add_card(struct pci_dev *pdev,
  388. const struct pci_device_id *ent)
  389. {
  390. struct sja1000_priv *priv;
  391. struct net_device *dev;
  392. struct plx_pci_card *card;
  393. struct plx_pci_card_info *ci;
  394. int err, i;
  395. u32 val;
  396. void __iomem *addr;
  397. ci = (struct plx_pci_card_info *)ent->driver_data;
  398. if (pci_enable_device(pdev) < 0) {
  399. dev_err(&pdev->dev, "Failed to enable PCI device\n");
  400. return -ENODEV;
  401. }
  402. dev_info(&pdev->dev, "Detected \"%s\" card at slot #%i\n",
  403. ci->name, PCI_SLOT(pdev->devfn));
  404. /* Allocate card structures to hold addresses, ... */
  405. card = kzalloc(sizeof(*card), GFP_KERNEL);
  406. if (!card) {
  407. dev_err(&pdev->dev, "Unable to allocate memory\n");
  408. pci_disable_device(pdev);
  409. return -ENOMEM;
  410. }
  411. pci_set_drvdata(pdev, card);
  412. card->channels = 0;
  413. /* Remap PLX90xx configuration space */
  414. addr = pci_iomap(pdev, ci->conf_map.bar, ci->conf_map.size);
  415. if (!addr) {
  416. err = -ENOMEM;
  417. dev_err(&pdev->dev, "Failed to remap configuration space "
  418. "(BAR%d)\n", ci->conf_map.bar);
  419. goto failure_cleanup;
  420. }
  421. card->conf_addr = addr + ci->conf_map.offset;
  422. ci->reset_func(pdev);
  423. card->reset_func = ci->reset_func;
  424. /* Detect available channels */
  425. for (i = 0; i < ci->channel_count; i++) {
  426. struct plx_pci_channel_map *cm = &ci->chan_map_tbl[i];
  427. dev = alloc_sja1000dev(0);
  428. if (!dev) {
  429. err = -ENOMEM;
  430. goto failure_cleanup;
  431. }
  432. card->net_dev[i] = dev;
  433. priv = netdev_priv(dev);
  434. priv->priv = card;
  435. priv->irq_flags = IRQF_SHARED;
  436. dev->irq = pdev->irq;
  437. /*
  438. * Remap IO space of the SJA1000 chips
  439. * This is device-dependent mapping
  440. */
  441. addr = pci_iomap(pdev, cm->bar, cm->size);
  442. if (!addr) {
  443. err = -ENOMEM;
  444. dev_err(&pdev->dev, "Failed to remap BAR%d\n", cm->bar);
  445. goto failure_cleanup;
  446. }
  447. priv->reg_base = addr + cm->offset;
  448. priv->read_reg = plx_pci_read_reg;
  449. priv->write_reg = plx_pci_write_reg;
  450. /* Check if channel is present */
  451. if (plx_pci_check_sja1000(priv)) {
  452. priv->can.clock.freq = ci->can_clock;
  453. priv->ocr = ci->ocr;
  454. priv->cdr = ci->cdr;
  455. SET_NETDEV_DEV(dev, &pdev->dev);
  456. /* Register SJA1000 device */
  457. err = register_sja1000dev(dev);
  458. if (err) {
  459. dev_err(&pdev->dev, "Registering device failed "
  460. "(err=%d)\n", err);
  461. free_sja1000dev(dev);
  462. goto failure_cleanup;
  463. }
  464. card->channels++;
  465. dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d "
  466. "registered as %s\n", i + 1, priv->reg_base,
  467. dev->irq, dev->name);
  468. } else {
  469. dev_err(&pdev->dev, "Channel #%d not detected\n",
  470. i + 1);
  471. free_sja1000dev(dev);
  472. }
  473. }
  474. if (!card->channels) {
  475. err = -ENODEV;
  476. goto failure_cleanup;
  477. }
  478. /*
  479. * Enable interrupts from PCI-card (PLX90xx) and enable Local_1,
  480. * Local_2 interrupts from the SJA1000 chips
  481. */
  482. if (pdev->device != PCI_DEVICE_ID_PLX_9056) {
  483. val = ioread32(card->conf_addr + PLX_INTCSR);
  484. if (pdev->subsystem_vendor == PCI_VENDOR_ID_ESDGMBH)
  485. val |= PLX_LINT1_EN | PLX_PCI_INT_EN;
  486. else
  487. val |= PLX_LINT1_EN | PLX_LINT2_EN | PLX_PCI_INT_EN;
  488. iowrite32(val, card->conf_addr + PLX_INTCSR);
  489. } else {
  490. iowrite32(PLX9056_LINTI | PLX9056_PCI_INT_EN,
  491. card->conf_addr + PLX9056_INTCSR);
  492. }
  493. return 0;
  494. failure_cleanup:
  495. dev_err(&pdev->dev, "Error: %d. Cleaning Up.\n", err);
  496. plx_pci_del_card(pdev);
  497. return err;
  498. }
  499. static struct pci_driver plx_pci_driver = {
  500. .name = DRV_NAME,
  501. .id_table = plx_pci_tbl,
  502. .probe = plx_pci_add_card,
  503. .remove = plx_pci_del_card,
  504. };
  505. static int __init plx_pci_init(void)
  506. {
  507. return pci_register_driver(&plx_pci_driver);
  508. }
  509. static void __exit plx_pci_exit(void)
  510. {
  511. pci_unregister_driver(&plx_pci_driver);
  512. }
  513. module_init(plx_pci_init);
  514. module_exit(plx_pci_exit);