sja1000.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 int sja1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
  205. {
  206. struct sja1000_priv *priv = netdev_priv(dev);
  207. struct net_device_stats *stats = &dev->stats;
  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. stats->tx_bytes += dlc;
  236. dev->trans_start = jiffies;
  237. can_put_echo_skb(skb, dev, 0);
  238. priv->write_reg(priv, REG_CMR, CMD_TR);
  239. return 0;
  240. }
  241. static void sja1000_rx(struct net_device *dev)
  242. {
  243. struct sja1000_priv *priv = netdev_priv(dev);
  244. struct net_device_stats *stats = &dev->stats;
  245. struct can_frame *cf;
  246. struct sk_buff *skb;
  247. uint8_t fi;
  248. uint8_t dreg;
  249. canid_t id;
  250. uint8_t dlc;
  251. int i;
  252. skb = dev_alloc_skb(sizeof(struct can_frame));
  253. if (skb == NULL)
  254. return;
  255. skb->dev = dev;
  256. skb->protocol = htons(ETH_P_CAN);
  257. fi = priv->read_reg(priv, REG_FI);
  258. dlc = fi & 0x0F;
  259. if (fi & FI_FF) {
  260. /* extended frame format (EFF) */
  261. dreg = EFF_BUF;
  262. id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
  263. | (priv->read_reg(priv, REG_ID2) << (5 + 8))
  264. | (priv->read_reg(priv, REG_ID3) << 5)
  265. | (priv->read_reg(priv, REG_ID4) >> 3);
  266. id |= CAN_EFF_FLAG;
  267. } else {
  268. /* standard frame format (SFF) */
  269. dreg = SFF_BUF;
  270. id = (priv->read_reg(priv, REG_ID1) << 3)
  271. | (priv->read_reg(priv, REG_ID2) >> 5);
  272. }
  273. if (fi & FI_RTR)
  274. id |= CAN_RTR_FLAG;
  275. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  276. memset(cf, 0, sizeof(struct can_frame));
  277. cf->can_id = id;
  278. cf->can_dlc = dlc;
  279. for (i = 0; i < dlc; i++)
  280. cf->data[i] = priv->read_reg(priv, dreg++);
  281. while (i < 8)
  282. cf->data[i++] = 0;
  283. /* release receive buffer */
  284. priv->write_reg(priv, REG_CMR, CMD_RRB);
  285. netif_rx(skb);
  286. dev->last_rx = jiffies;
  287. stats->rx_packets++;
  288. stats->rx_bytes += dlc;
  289. }
  290. static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
  291. {
  292. struct sja1000_priv *priv = netdev_priv(dev);
  293. struct net_device_stats *stats = &dev->stats;
  294. struct can_frame *cf;
  295. struct sk_buff *skb;
  296. enum can_state state = priv->can.state;
  297. uint8_t ecc, alc;
  298. skb = dev_alloc_skb(sizeof(struct can_frame));
  299. if (skb == NULL)
  300. return -ENOMEM;
  301. skb->dev = dev;
  302. skb->protocol = htons(ETH_P_CAN);
  303. cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
  304. memset(cf, 0, sizeof(struct can_frame));
  305. cf->can_id = CAN_ERR_FLAG;
  306. cf->can_dlc = CAN_ERR_DLC;
  307. if (isrc & IRQ_DOI) {
  308. /* data overrun interrupt */
  309. dev_dbg(dev->dev.parent, "data overrun interrupt\n");
  310. cf->can_id |= CAN_ERR_CRTL;
  311. cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
  312. stats->rx_over_errors++;
  313. stats->rx_errors++;
  314. priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
  315. }
  316. if (isrc & IRQ_EI) {
  317. /* error warning interrupt */
  318. dev_dbg(dev->dev.parent, "error warning interrupt\n");
  319. if (status & SR_BS) {
  320. state = CAN_STATE_BUS_OFF;
  321. cf->can_id |= CAN_ERR_BUSOFF;
  322. can_bus_off(dev);
  323. } else if (status & SR_ES) {
  324. state = CAN_STATE_ERROR_WARNING;
  325. } else
  326. state = CAN_STATE_ERROR_ACTIVE;
  327. }
  328. if (isrc & IRQ_BEI) {
  329. /* bus error interrupt */
  330. priv->can.can_stats.bus_error++;
  331. stats->rx_errors++;
  332. ecc = priv->read_reg(priv, REG_ECC);
  333. cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
  334. switch (ecc & ECC_MASK) {
  335. case ECC_BIT:
  336. cf->data[2] |= CAN_ERR_PROT_BIT;
  337. break;
  338. case ECC_FORM:
  339. cf->data[2] |= CAN_ERR_PROT_FORM;
  340. break;
  341. case ECC_STUFF:
  342. cf->data[2] |= CAN_ERR_PROT_STUFF;
  343. break;
  344. default:
  345. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  346. cf->data[3] = ecc & ECC_SEG;
  347. break;
  348. }
  349. /* Error occured during transmission? */
  350. if ((ecc & ECC_DIR) == 0)
  351. cf->data[2] |= CAN_ERR_PROT_TX;
  352. }
  353. if (isrc & IRQ_EPI) {
  354. /* error passive interrupt */
  355. dev_dbg(dev->dev.parent, "error passive interrupt\n");
  356. if (status & SR_ES)
  357. state = CAN_STATE_ERROR_PASSIVE;
  358. else
  359. state = CAN_STATE_ERROR_ACTIVE;
  360. }
  361. if (isrc & IRQ_ALI) {
  362. /* arbitration lost interrupt */
  363. dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
  364. alc = priv->read_reg(priv, REG_ALC);
  365. priv->can.can_stats.arbitration_lost++;
  366. stats->rx_errors++;
  367. cf->can_id |= CAN_ERR_LOSTARB;
  368. cf->data[0] = alc & 0x1f;
  369. }
  370. if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
  371. state == CAN_STATE_ERROR_PASSIVE)) {
  372. uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
  373. uint8_t txerr = priv->read_reg(priv, REG_TXERR);
  374. cf->can_id |= CAN_ERR_CRTL;
  375. if (state == CAN_STATE_ERROR_WARNING) {
  376. priv->can.can_stats.error_warning++;
  377. cf->data[1] = (txerr > rxerr) ?
  378. CAN_ERR_CRTL_TX_WARNING :
  379. CAN_ERR_CRTL_RX_WARNING;
  380. } else {
  381. priv->can.can_stats.error_passive++;
  382. cf->data[1] = (txerr > rxerr) ?
  383. CAN_ERR_CRTL_TX_PASSIVE :
  384. CAN_ERR_CRTL_RX_PASSIVE;
  385. }
  386. }
  387. priv->can.state = state;
  388. netif_rx(skb);
  389. dev->last_rx = jiffies;
  390. stats->rx_packets++;
  391. stats->rx_bytes += cf->can_dlc;
  392. return 0;
  393. }
  394. irqreturn_t sja1000_interrupt(int irq, void *dev_id)
  395. {
  396. struct net_device *dev = (struct net_device *)dev_id;
  397. struct sja1000_priv *priv = netdev_priv(dev);
  398. struct net_device_stats *stats = &dev->stats;
  399. uint8_t isrc, status;
  400. int n = 0;
  401. /* Shared interrupts and IRQ off? */
  402. if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
  403. return IRQ_NONE;
  404. if (priv->pre_irq)
  405. priv->pre_irq(priv);
  406. while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
  407. n++;
  408. status = priv->read_reg(priv, REG_SR);
  409. if (isrc & IRQ_WUI)
  410. dev_warn(dev->dev.parent, "wakeup interrupt\n");
  411. if (isrc & IRQ_TI) {
  412. /* transmission complete interrupt */
  413. stats->tx_packets++;
  414. can_get_echo_skb(dev, 0);
  415. netif_wake_queue(dev);
  416. }
  417. if (isrc & IRQ_RI) {
  418. /* receive interrupt */
  419. while (status & SR_RBS) {
  420. sja1000_rx(dev);
  421. status = priv->read_reg(priv, REG_SR);
  422. }
  423. }
  424. if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
  425. /* error interrupt */
  426. if (sja1000_err(dev, isrc, status))
  427. break;
  428. }
  429. }
  430. if (priv->post_irq)
  431. priv->post_irq(priv);
  432. if (n >= SJA1000_MAX_IRQ)
  433. dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
  434. return (n) ? IRQ_HANDLED : IRQ_NONE;
  435. }
  436. EXPORT_SYMBOL_GPL(sja1000_interrupt);
  437. static int sja1000_open(struct net_device *dev)
  438. {
  439. struct sja1000_priv *priv = netdev_priv(dev);
  440. int err;
  441. /* set chip into reset mode */
  442. set_reset_mode(dev);
  443. /* common open */
  444. err = open_candev(dev);
  445. if (err)
  446. return err;
  447. /* register interrupt handler, if not done by the device driver */
  448. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
  449. err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags,
  450. dev->name, (void *)dev);
  451. if (err) {
  452. close_candev(dev);
  453. return -EAGAIN;
  454. }
  455. }
  456. /* init and start chi */
  457. sja1000_start(dev);
  458. priv->open_time = jiffies;
  459. netif_start_queue(dev);
  460. return 0;
  461. }
  462. static int sja1000_close(struct net_device *dev)
  463. {
  464. struct sja1000_priv *priv = netdev_priv(dev);
  465. netif_stop_queue(dev);
  466. set_reset_mode(dev);
  467. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER))
  468. free_irq(dev->irq, (void *)dev);
  469. close_candev(dev);
  470. priv->open_time = 0;
  471. return 0;
  472. }
  473. struct net_device *alloc_sja1000dev(int sizeof_priv)
  474. {
  475. struct net_device *dev;
  476. struct sja1000_priv *priv;
  477. dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv);
  478. if (!dev)
  479. return NULL;
  480. priv = netdev_priv(dev);
  481. priv->dev = dev;
  482. priv->can.bittiming_const = &sja1000_bittiming_const;
  483. priv->can.do_set_bittiming = sja1000_set_bittiming;
  484. priv->can.do_set_mode = sja1000_set_mode;
  485. if (sizeof_priv)
  486. priv->priv = (void *)priv + sizeof(struct sja1000_priv);
  487. return dev;
  488. }
  489. EXPORT_SYMBOL_GPL(alloc_sja1000dev);
  490. void free_sja1000dev(struct net_device *dev)
  491. {
  492. free_candev(dev);
  493. }
  494. EXPORT_SYMBOL_GPL(free_sja1000dev);
  495. static const struct net_device_ops sja1000_netdev_ops = {
  496. .ndo_open = sja1000_open,
  497. .ndo_stop = sja1000_close,
  498. .ndo_start_xmit = sja1000_start_xmit,
  499. };
  500. int register_sja1000dev(struct net_device *dev)
  501. {
  502. if (!sja1000_probe_chip(dev))
  503. return -ENODEV;
  504. dev->flags |= IFF_ECHO; /* we support local echo */
  505. dev->netdev_ops = &sja1000_netdev_ops;
  506. set_reset_mode(dev);
  507. chipset_init(dev);
  508. return register_candev(dev);
  509. }
  510. EXPORT_SYMBOL_GPL(register_sja1000dev);
  511. void unregister_sja1000dev(struct net_device *dev)
  512. {
  513. set_reset_mode(dev);
  514. unregister_candev(dev);
  515. }
  516. EXPORT_SYMBOL_GPL(unregister_sja1000dev);
  517. static __init int sja1000_init(void)
  518. {
  519. printk(KERN_INFO "%s CAN netdevice driver\n", DRV_NAME);
  520. return 0;
  521. }
  522. module_init(sja1000_init);
  523. static __exit void sja1000_exit(void)
  524. {
  525. printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
  526. }
  527. module_exit(sja1000_exit);