sja1000.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * sja1000.c - Philips SJA1000 network device driver
  3. *
  4. * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,
  5. * 38106 Braunschweig, GERMANY
  6. *
  7. * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of Volkswagen nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * Alternatively, provided that this notice is retained in full, this
  23. * software may be distributed under the terms of the GNU General
  24. * Public License ("GPL") version 2, in which case the provisions of the
  25. * GPL apply INSTEAD OF those given above.
  26. *
  27. * The provided data structures and external interfaces from this code
  28. * are not restricted to be used by modules with a GPL compatible license.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  36. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  37. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  38. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  41. * DAMAGE.
  42. *
  43. * Send feedback to <socketcan-users@lists.berlios.de>
  44. *
  45. */
  46. #include <linux/module.h>
  47. #include <linux/init.h>
  48. #include <linux/kernel.h>
  49. #include <linux/sched.h>
  50. #include <linux/types.h>
  51. #include <linux/fcntl.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/ptrace.h>
  54. #include <linux/string.h>
  55. #include <linux/errno.h>
  56. #include <linux/netdevice.h>
  57. #include <linux/if_arp.h>
  58. #include <linux/if_ether.h>
  59. #include <linux/skbuff.h>
  60. #include <linux/delay.h>
  61. #include <linux/can.h>
  62. #include <linux/can/dev.h>
  63. #include <linux/can/error.h>
  64. #include "sja1000.h"
  65. #define DRV_NAME "sja1000"
  66. MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
  67. MODULE_LICENSE("Dual BSD/GPL");
  68. MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver");
  69. static struct can_bittiming_const sja1000_bittiming_const = {
  70. .name = DRV_NAME,
  71. .tseg1_min = 1,
  72. .tseg1_max = 16,
  73. .tseg2_min = 1,
  74. .tseg2_max = 8,
  75. .sjw_max = 4,
  76. .brp_min = 1,
  77. .brp_max = 64,
  78. .brp_inc = 1,
  79. };
  80. static int sja1000_probe_chip(struct net_device *dev)
  81. {
  82. struct sja1000_priv *priv = netdev_priv(dev);
  83. if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
  84. printk(KERN_INFO "%s: probing @0x%lX failed\n",
  85. DRV_NAME, dev->base_addr);
  86. return 0;
  87. }
  88. return -1;
  89. }
  90. static void set_reset_mode(struct net_device *dev)
  91. {
  92. struct sja1000_priv *priv = netdev_priv(dev);
  93. unsigned char status = priv->read_reg(priv, REG_MOD);
  94. int i;
  95. /* disable interrupts */
  96. priv->write_reg(priv, REG_IER, IRQ_OFF);
  97. for (i = 0; i < 100; i++) {
  98. /* check reset bit */
  99. if (status & MOD_RM) {
  100. priv->can.state = CAN_STATE_STOPPED;
  101. return;
  102. }
  103. priv->write_reg(priv, REG_MOD, MOD_RM); /* reset chip */
  104. udelay(10);
  105. status = priv->read_reg(priv, REG_MOD);
  106. }
  107. dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
  108. }
  109. static void set_normal_mode(struct net_device *dev)
  110. {
  111. struct sja1000_priv *priv = netdev_priv(dev);
  112. unsigned char status = priv->read_reg(priv, REG_MOD);
  113. int i;
  114. for (i = 0; i < 100; i++) {
  115. /* check reset bit */
  116. if ((status & MOD_RM) == 0) {
  117. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  118. /* enable all interrupts */
  119. priv->write_reg(priv, REG_IER, IRQ_ALL);
  120. return;
  121. }
  122. /* set chip to normal mode */
  123. priv->write_reg(priv, REG_MOD, 0x00);
  124. udelay(10);
  125. status = priv->read_reg(priv, REG_MOD);
  126. }
  127. dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
  128. }
  129. static void sja1000_start(struct net_device *dev)
  130. {
  131. struct sja1000_priv *priv = netdev_priv(dev);
  132. /* leave reset mode */
  133. if (priv->can.state != CAN_STATE_STOPPED)
  134. set_reset_mode(dev);
  135. /* Clear error counters and error code capture */
  136. priv->write_reg(priv, REG_TXERR, 0x0);
  137. priv->write_reg(priv, REG_RXERR, 0x0);
  138. priv->read_reg(priv, REG_ECC);
  139. /* leave reset mode */
  140. set_normal_mode(dev);
  141. }
  142. static int sja1000_set_mode(struct net_device *dev, enum can_mode mode)
  143. {
  144. struct sja1000_priv *priv = netdev_priv(dev);
  145. if (!priv->open_time)
  146. return -EINVAL;
  147. switch (mode) {
  148. case CAN_MODE_START:
  149. sja1000_start(dev);
  150. if (netif_queue_stopped(dev))
  151. netif_wake_queue(dev);
  152. break;
  153. default:
  154. return -EOPNOTSUPP;
  155. }
  156. return 0;
  157. }
  158. static int sja1000_set_bittiming(struct net_device *dev)
  159. {
  160. struct sja1000_priv *priv = netdev_priv(dev);
  161. struct can_bittiming *bt = &priv->can.bittiming;
  162. u8 btr0, btr1;
  163. btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
  164. btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
  165. (((bt->phase_seg2 - 1) & 0x7) << 4);
  166. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
  167. btr1 |= 0x80;
  168. dev_info(dev->dev.parent,
  169. "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
  170. priv->write_reg(priv, REG_BTR0, btr0);
  171. priv->write_reg(priv, REG_BTR1, btr1);
  172. return 0;
  173. }
  174. /*
  175. * initialize SJA1000 chip:
  176. * - reset chip
  177. * - set output mode
  178. * - set baudrate
  179. * - enable interrupts
  180. * - start operating mode
  181. */
  182. static void chipset_init(struct net_device *dev)
  183. {
  184. struct sja1000_priv *priv = netdev_priv(dev);
  185. /* set clock divider and output control register */
  186. priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
  187. /* set acceptance filter (accept all) */
  188. priv->write_reg(priv, REG_ACCC0, 0x00);
  189. priv->write_reg(priv, REG_ACCC1, 0x00);
  190. priv->write_reg(priv, REG_ACCC2, 0x00);
  191. priv->write_reg(priv, REG_ACCC3, 0x00);
  192. priv->write_reg(priv, REG_ACCM0, 0xFF);
  193. priv->write_reg(priv, REG_ACCM1, 0xFF);
  194. priv->write_reg(priv, REG_ACCM2, 0xFF);
  195. priv->write_reg(priv, REG_ACCM3, 0xFF);
  196. priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
  197. }
  198. /*
  199. * transmit a CAN message
  200. * message layout in the sk_buff should be like this:
  201. * xx xx xx xx ff ll 00 11 22 33 44 55 66 77
  202. * [ can-id ] [flags] [len] [can data (up to 8 bytes]
  203. */
  204. static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
  205. struct net_device *dev)
  206. {
  207. struct sja1000_priv *priv = netdev_priv(dev);
  208. struct can_frame *cf = (struct can_frame *)skb->data;
  209. uint8_t fi;
  210. uint8_t dlc;
  211. canid_t id;
  212. uint8_t dreg;
  213. int i;
  214. netif_stop_queue(dev);
  215. fi = dlc = cf->can_dlc;
  216. id = cf->can_id;
  217. if (id & CAN_RTR_FLAG)
  218. fi |= FI_RTR;
  219. if (id & CAN_EFF_FLAG) {
  220. fi |= FI_FF;
  221. dreg = EFF_BUF;
  222. priv->write_reg(priv, REG_FI, fi);
  223. priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
  224. priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
  225. priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
  226. priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
  227. } else {
  228. dreg = SFF_BUF;
  229. priv->write_reg(priv, REG_FI, fi);
  230. priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
  231. priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
  232. }
  233. for (i = 0; i < dlc; i++)
  234. priv->write_reg(priv, dreg++, cf->data[i]);
  235. dev->trans_start = jiffies;
  236. can_put_echo_skb(skb, dev, 0);
  237. priv->write_reg(priv, REG_CMR, CMD_TR);
  238. return NETDEV_TX_OK;
  239. }
  240. static void sja1000_rx(struct net_device *dev)
  241. {
  242. struct sja1000_priv *priv = netdev_priv(dev);
  243. struct net_device_stats *stats = &dev->stats;
  244. struct can_frame *cf;
  245. struct sk_buff *skb;
  246. uint8_t fi;
  247. uint8_t dreg;
  248. canid_t id;
  249. uint8_t dlc;
  250. int i;
  251. skb = dev_alloc_skb(sizeof(struct can_frame));
  252. if (skb == NULL)
  253. return;
  254. skb->dev = dev;
  255. skb->protocol = htons(ETH_P_CAN);
  256. fi = priv->read_reg(priv, REG_FI);
  257. dlc = fi & 0x0F;
  258. if (fi & FI_FF) {
  259. /* extended frame format (EFF) */
  260. dreg = EFF_BUF;
  261. id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
  262. | (priv->read_reg(priv, REG_ID2) << (5 + 8))
  263. | (priv->read_reg(priv, REG_ID3) << 5)
  264. | (priv->read_reg(priv, REG_ID4) >> 3);
  265. id |= CAN_EFF_FLAG;
  266. } else {
  267. /* standard frame format (SFF) */
  268. dreg = SFF_BUF;
  269. id = (priv->read_reg(priv, REG_ID1) << 3)
  270. | (priv->read_reg(priv, REG_ID2) >> 5);
  271. }
  272. if (fi & FI_RTR)
  273. id |= CAN_RTR_FLAG;
  274. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  275. memset(cf, 0, sizeof(struct can_frame));
  276. cf->can_id = id;
  277. cf->can_dlc = dlc;
  278. for (i = 0; i < dlc; i++)
  279. cf->data[i] = priv->read_reg(priv, dreg++);
  280. while (i < 8)
  281. cf->data[i++] = 0;
  282. /* release receive buffer */
  283. priv->write_reg(priv, REG_CMR, CMD_RRB);
  284. netif_rx(skb);
  285. stats->rx_packets++;
  286. stats->rx_bytes += dlc;
  287. }
  288. static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
  289. {
  290. struct sja1000_priv *priv = netdev_priv(dev);
  291. struct net_device_stats *stats = &dev->stats;
  292. struct can_frame *cf;
  293. struct sk_buff *skb;
  294. enum can_state state = priv->can.state;
  295. uint8_t ecc, alc;
  296. skb = dev_alloc_skb(sizeof(struct can_frame));
  297. if (skb == NULL)
  298. return -ENOMEM;
  299. skb->dev = dev;
  300. skb->protocol = htons(ETH_P_CAN);
  301. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  302. memset(cf, 0, sizeof(struct can_frame));
  303. cf->can_id = CAN_ERR_FLAG;
  304. cf->can_dlc = CAN_ERR_DLC;
  305. if (isrc & IRQ_DOI) {
  306. /* data overrun interrupt */
  307. dev_dbg(dev->dev.parent, "data overrun interrupt\n");
  308. cf->can_id |= CAN_ERR_CRTL;
  309. cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
  310. stats->rx_over_errors++;
  311. stats->rx_errors++;
  312. priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
  313. }
  314. if (isrc & IRQ_EI) {
  315. /* error warning interrupt */
  316. dev_dbg(dev->dev.parent, "error warning interrupt\n");
  317. if (status & SR_BS) {
  318. state = CAN_STATE_BUS_OFF;
  319. cf->can_id |= CAN_ERR_BUSOFF;
  320. can_bus_off(dev);
  321. } else if (status & SR_ES) {
  322. state = CAN_STATE_ERROR_WARNING;
  323. } else
  324. state = CAN_STATE_ERROR_ACTIVE;
  325. }
  326. if (isrc & IRQ_BEI) {
  327. /* bus error interrupt */
  328. priv->can.can_stats.bus_error++;
  329. stats->rx_errors++;
  330. ecc = priv->read_reg(priv, REG_ECC);
  331. cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
  332. switch (ecc & ECC_MASK) {
  333. case ECC_BIT:
  334. cf->data[2] |= CAN_ERR_PROT_BIT;
  335. break;
  336. case ECC_FORM:
  337. cf->data[2] |= CAN_ERR_PROT_FORM;
  338. break;
  339. case ECC_STUFF:
  340. cf->data[2] |= CAN_ERR_PROT_STUFF;
  341. break;
  342. default:
  343. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  344. cf->data[3] = ecc & ECC_SEG;
  345. break;
  346. }
  347. /* Error occured during transmission? */
  348. if ((ecc & ECC_DIR) == 0)
  349. cf->data[2] |= CAN_ERR_PROT_TX;
  350. }
  351. if (isrc & IRQ_EPI) {
  352. /* error passive interrupt */
  353. dev_dbg(dev->dev.parent, "error passive interrupt\n");
  354. if (status & SR_ES)
  355. state = CAN_STATE_ERROR_PASSIVE;
  356. else
  357. state = CAN_STATE_ERROR_ACTIVE;
  358. }
  359. if (isrc & IRQ_ALI) {
  360. /* arbitration lost interrupt */
  361. dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
  362. alc = priv->read_reg(priv, REG_ALC);
  363. priv->can.can_stats.arbitration_lost++;
  364. stats->tx_errors++;
  365. cf->can_id |= CAN_ERR_LOSTARB;
  366. cf->data[0] = alc & 0x1f;
  367. }
  368. if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
  369. state == CAN_STATE_ERROR_PASSIVE)) {
  370. uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
  371. uint8_t txerr = priv->read_reg(priv, REG_TXERR);
  372. cf->can_id |= CAN_ERR_CRTL;
  373. if (state == CAN_STATE_ERROR_WARNING) {
  374. priv->can.can_stats.error_warning++;
  375. cf->data[1] = (txerr > rxerr) ?
  376. CAN_ERR_CRTL_TX_WARNING :
  377. CAN_ERR_CRTL_RX_WARNING;
  378. } else {
  379. priv->can.can_stats.error_passive++;
  380. cf->data[1] = (txerr > rxerr) ?
  381. CAN_ERR_CRTL_TX_PASSIVE :
  382. CAN_ERR_CRTL_RX_PASSIVE;
  383. }
  384. }
  385. priv->can.state = state;
  386. netif_rx(skb);
  387. stats->rx_packets++;
  388. stats->rx_bytes += cf->can_dlc;
  389. return 0;
  390. }
  391. irqreturn_t sja1000_interrupt(int irq, void *dev_id)
  392. {
  393. struct net_device *dev = (struct net_device *)dev_id;
  394. struct sja1000_priv *priv = netdev_priv(dev);
  395. struct net_device_stats *stats = &dev->stats;
  396. uint8_t isrc, status;
  397. int n = 0;
  398. /* Shared interrupts and IRQ off? */
  399. if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
  400. return IRQ_NONE;
  401. if (priv->pre_irq)
  402. priv->pre_irq(priv);
  403. while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
  404. n++;
  405. status = priv->read_reg(priv, REG_SR);
  406. if (isrc & IRQ_WUI)
  407. dev_warn(dev->dev.parent, "wakeup interrupt\n");
  408. if (isrc & IRQ_TI) {
  409. /* transmission complete interrupt */
  410. stats->tx_bytes += priv->read_reg(priv, REG_FI) & 0xf;
  411. stats->tx_packets++;
  412. can_get_echo_skb(dev, 0);
  413. netif_wake_queue(dev);
  414. }
  415. if (isrc & IRQ_RI) {
  416. /* receive interrupt */
  417. while (status & SR_RBS) {
  418. sja1000_rx(dev);
  419. status = priv->read_reg(priv, REG_SR);
  420. }
  421. }
  422. if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
  423. /* error interrupt */
  424. if (sja1000_err(dev, isrc, status))
  425. break;
  426. }
  427. }
  428. if (priv->post_irq)
  429. priv->post_irq(priv);
  430. if (n >= SJA1000_MAX_IRQ)
  431. dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
  432. return (n) ? IRQ_HANDLED : IRQ_NONE;
  433. }
  434. EXPORT_SYMBOL_GPL(sja1000_interrupt);
  435. static int sja1000_open(struct net_device *dev)
  436. {
  437. struct sja1000_priv *priv = netdev_priv(dev);
  438. int err;
  439. /* set chip into reset mode */
  440. set_reset_mode(dev);
  441. /* common open */
  442. err = open_candev(dev);
  443. if (err)
  444. return err;
  445. /* register interrupt handler, if not done by the device driver */
  446. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
  447. err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags,
  448. dev->name, (void *)dev);
  449. if (err) {
  450. close_candev(dev);
  451. return -EAGAIN;
  452. }
  453. }
  454. /* init and start chi */
  455. sja1000_start(dev);
  456. priv->open_time = jiffies;
  457. netif_start_queue(dev);
  458. return 0;
  459. }
  460. static int sja1000_close(struct net_device *dev)
  461. {
  462. struct sja1000_priv *priv = netdev_priv(dev);
  463. netif_stop_queue(dev);
  464. set_reset_mode(dev);
  465. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER))
  466. free_irq(dev->irq, (void *)dev);
  467. close_candev(dev);
  468. priv->open_time = 0;
  469. return 0;
  470. }
  471. struct net_device *alloc_sja1000dev(int sizeof_priv)
  472. {
  473. struct net_device *dev;
  474. struct sja1000_priv *priv;
  475. dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv);
  476. if (!dev)
  477. return NULL;
  478. priv = netdev_priv(dev);
  479. priv->dev = dev;
  480. priv->can.bittiming_const = &sja1000_bittiming_const;
  481. priv->can.do_set_bittiming = sja1000_set_bittiming;
  482. priv->can.do_set_mode = sja1000_set_mode;
  483. if (sizeof_priv)
  484. priv->priv = (void *)priv + sizeof(struct sja1000_priv);
  485. return dev;
  486. }
  487. EXPORT_SYMBOL_GPL(alloc_sja1000dev);
  488. void free_sja1000dev(struct net_device *dev)
  489. {
  490. free_candev(dev);
  491. }
  492. EXPORT_SYMBOL_GPL(free_sja1000dev);
  493. static const struct net_device_ops sja1000_netdev_ops = {
  494. .ndo_open = sja1000_open,
  495. .ndo_stop = sja1000_close,
  496. .ndo_start_xmit = sja1000_start_xmit,
  497. };
  498. int register_sja1000dev(struct net_device *dev)
  499. {
  500. if (!sja1000_probe_chip(dev))
  501. return -ENODEV;
  502. dev->flags |= IFF_ECHO; /* we support local echo */
  503. dev->netdev_ops = &sja1000_netdev_ops;
  504. set_reset_mode(dev);
  505. chipset_init(dev);
  506. return register_candev(dev);
  507. }
  508. EXPORT_SYMBOL_GPL(register_sja1000dev);
  509. void unregister_sja1000dev(struct net_device *dev)
  510. {
  511. set_reset_mode(dev);
  512. unregister_candev(dev);
  513. }
  514. EXPORT_SYMBOL_GPL(unregister_sja1000dev);
  515. static __init int sja1000_init(void)
  516. {
  517. printk(KERN_INFO "%s CAN netdevice driver\n", DRV_NAME);
  518. return 0;
  519. }
  520. module_init(sja1000_init);
  521. static __exit void sja1000_exit(void)
  522. {
  523. printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
  524. }
  525. module_exit(sja1000_exit);