sja1000.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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/dev.h>
  62. #include <linux/can/error.h>
  63. #include "sja1000.h"
  64. #define DRV_NAME "sja1000"
  65. MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
  66. MODULE_LICENSE("Dual BSD/GPL");
  67. MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver");
  68. static struct can_bittiming_const sja1000_bittiming_const = {
  69. .name = DRV_NAME,
  70. .tseg1_min = 1,
  71. .tseg1_max = 16,
  72. .tseg2_min = 1,
  73. .tseg2_max = 8,
  74. .sjw_max = 4,
  75. .brp_min = 1,
  76. .brp_max = 64,
  77. .brp_inc = 1,
  78. };
  79. static int sja1000_probe_chip(struct net_device *dev)
  80. {
  81. struct sja1000_priv *priv = netdev_priv(dev);
  82. if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
  83. printk(KERN_INFO "%s: probing @0x%lX failed\n",
  84. DRV_NAME, dev->base_addr);
  85. return 0;
  86. }
  87. return -1;
  88. }
  89. static void set_reset_mode(struct net_device *dev)
  90. {
  91. struct sja1000_priv *priv = netdev_priv(dev);
  92. unsigned char status = priv->read_reg(priv, REG_MOD);
  93. int i;
  94. /* disable interrupts */
  95. priv->write_reg(priv, REG_IER, IRQ_OFF);
  96. for (i = 0; i < 100; i++) {
  97. /* check reset bit */
  98. if (status & MOD_RM) {
  99. priv->can.state = CAN_STATE_STOPPED;
  100. return;
  101. }
  102. priv->write_reg(priv, REG_MOD, MOD_RM); /* reset chip */
  103. udelay(10);
  104. status = priv->read_reg(priv, REG_MOD);
  105. }
  106. dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
  107. }
  108. static void set_normal_mode(struct net_device *dev)
  109. {
  110. struct sja1000_priv *priv = netdev_priv(dev);
  111. unsigned char status = priv->read_reg(priv, REG_MOD);
  112. int i;
  113. for (i = 0; i < 100; i++) {
  114. /* check reset bit */
  115. if ((status & MOD_RM) == 0) {
  116. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  117. /* enable interrupts */
  118. if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
  119. priv->write_reg(priv, REG_IER, IRQ_ALL);
  120. else
  121. priv->write_reg(priv, REG_IER,
  122. IRQ_ALL & ~IRQ_BEI);
  123. return;
  124. }
  125. /* set chip to normal mode */
  126. priv->write_reg(priv, REG_MOD, 0x00);
  127. udelay(10);
  128. status = priv->read_reg(priv, REG_MOD);
  129. }
  130. dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
  131. }
  132. static void sja1000_start(struct net_device *dev)
  133. {
  134. struct sja1000_priv *priv = netdev_priv(dev);
  135. /* leave reset mode */
  136. if (priv->can.state != CAN_STATE_STOPPED)
  137. set_reset_mode(dev);
  138. /* Clear error counters and error code capture */
  139. priv->write_reg(priv, REG_TXERR, 0x0);
  140. priv->write_reg(priv, REG_RXERR, 0x0);
  141. priv->read_reg(priv, REG_ECC);
  142. /* leave reset mode */
  143. set_normal_mode(dev);
  144. }
  145. static int sja1000_set_mode(struct net_device *dev, enum can_mode mode)
  146. {
  147. struct sja1000_priv *priv = netdev_priv(dev);
  148. if (!priv->open_time)
  149. return -EINVAL;
  150. switch (mode) {
  151. case CAN_MODE_START:
  152. sja1000_start(dev);
  153. if (netif_queue_stopped(dev))
  154. netif_wake_queue(dev);
  155. break;
  156. default:
  157. return -EOPNOTSUPP;
  158. }
  159. return 0;
  160. }
  161. static int sja1000_set_bittiming(struct net_device *dev)
  162. {
  163. struct sja1000_priv *priv = netdev_priv(dev);
  164. struct can_bittiming *bt = &priv->can.bittiming;
  165. u8 btr0, btr1;
  166. btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
  167. btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
  168. (((bt->phase_seg2 - 1) & 0x7) << 4);
  169. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
  170. btr1 |= 0x80;
  171. dev_info(dev->dev.parent,
  172. "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
  173. priv->write_reg(priv, REG_BTR0, btr0);
  174. priv->write_reg(priv, REG_BTR1, btr1);
  175. return 0;
  176. }
  177. static int sja1000_get_berr_counter(const struct net_device *dev,
  178. struct can_berr_counter *bec)
  179. {
  180. struct sja1000_priv *priv = netdev_priv(dev);
  181. bec->txerr = priv->read_reg(priv, REG_TXERR);
  182. bec->rxerr = priv->read_reg(priv, REG_RXERR);
  183. return 0;
  184. }
  185. /*
  186. * initialize SJA1000 chip:
  187. * - reset chip
  188. * - set output mode
  189. * - set baudrate
  190. * - enable interrupts
  191. * - start operating mode
  192. */
  193. static void chipset_init(struct net_device *dev)
  194. {
  195. struct sja1000_priv *priv = netdev_priv(dev);
  196. /* set clock divider and output control register */
  197. priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
  198. /* set acceptance filter (accept all) */
  199. priv->write_reg(priv, REG_ACCC0, 0x00);
  200. priv->write_reg(priv, REG_ACCC1, 0x00);
  201. priv->write_reg(priv, REG_ACCC2, 0x00);
  202. priv->write_reg(priv, REG_ACCC3, 0x00);
  203. priv->write_reg(priv, REG_ACCM0, 0xFF);
  204. priv->write_reg(priv, REG_ACCM1, 0xFF);
  205. priv->write_reg(priv, REG_ACCM2, 0xFF);
  206. priv->write_reg(priv, REG_ACCM3, 0xFF);
  207. priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
  208. }
  209. /*
  210. * transmit a CAN message
  211. * message layout in the sk_buff should be like this:
  212. * xx xx xx xx ff ll 00 11 22 33 44 55 66 77
  213. * [ can-id ] [flags] [len] [can data (up to 8 bytes]
  214. */
  215. static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
  216. struct net_device *dev)
  217. {
  218. struct sja1000_priv *priv = netdev_priv(dev);
  219. struct can_frame *cf = (struct can_frame *)skb->data;
  220. uint8_t fi;
  221. uint8_t dlc;
  222. canid_t id;
  223. uint8_t dreg;
  224. int i;
  225. if (can_dropped_invalid_skb(dev, skb))
  226. return NETDEV_TX_OK;
  227. netif_stop_queue(dev);
  228. fi = dlc = cf->can_dlc;
  229. id = cf->can_id;
  230. if (id & CAN_RTR_FLAG)
  231. fi |= FI_RTR;
  232. if (id & CAN_EFF_FLAG) {
  233. fi |= FI_FF;
  234. dreg = EFF_BUF;
  235. priv->write_reg(priv, REG_FI, fi);
  236. priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
  237. priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
  238. priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
  239. priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
  240. } else {
  241. dreg = SFF_BUF;
  242. priv->write_reg(priv, REG_FI, fi);
  243. priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
  244. priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
  245. }
  246. for (i = 0; i < dlc; i++)
  247. priv->write_reg(priv, dreg++, cf->data[i]);
  248. dev->trans_start = jiffies;
  249. can_put_echo_skb(skb, dev, 0);
  250. priv->write_reg(priv, REG_CMR, CMD_TR);
  251. return NETDEV_TX_OK;
  252. }
  253. static void sja1000_rx(struct net_device *dev)
  254. {
  255. struct sja1000_priv *priv = netdev_priv(dev);
  256. struct net_device_stats *stats = &dev->stats;
  257. struct can_frame *cf;
  258. struct sk_buff *skb;
  259. uint8_t fi;
  260. uint8_t dreg;
  261. canid_t id;
  262. int i;
  263. /* create zero'ed CAN frame buffer */
  264. skb = alloc_can_skb(dev, &cf);
  265. if (skb == NULL)
  266. return;
  267. fi = priv->read_reg(priv, REG_FI);
  268. if (fi & FI_FF) {
  269. /* extended frame format (EFF) */
  270. dreg = EFF_BUF;
  271. id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
  272. | (priv->read_reg(priv, REG_ID2) << (5 + 8))
  273. | (priv->read_reg(priv, REG_ID3) << 5)
  274. | (priv->read_reg(priv, REG_ID4) >> 3);
  275. id |= CAN_EFF_FLAG;
  276. } else {
  277. /* standard frame format (SFF) */
  278. dreg = SFF_BUF;
  279. id = (priv->read_reg(priv, REG_ID1) << 3)
  280. | (priv->read_reg(priv, REG_ID2) >> 5);
  281. }
  282. if (fi & FI_RTR) {
  283. id |= CAN_RTR_FLAG;
  284. } else {
  285. cf->can_dlc = get_can_dlc(fi & 0x0F);
  286. for (i = 0; i < cf->can_dlc; i++)
  287. cf->data[i] = priv->read_reg(priv, dreg++);
  288. }
  289. cf->can_id = id;
  290. /* release receive buffer */
  291. priv->write_reg(priv, REG_CMR, CMD_RRB);
  292. netif_rx(skb);
  293. stats->rx_packets++;
  294. stats->rx_bytes += cf->can_dlc;
  295. }
  296. static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
  297. {
  298. struct sja1000_priv *priv = netdev_priv(dev);
  299. struct net_device_stats *stats = &dev->stats;
  300. struct can_frame *cf;
  301. struct sk_buff *skb;
  302. enum can_state state = priv->can.state;
  303. uint8_t ecc, alc;
  304. skb = alloc_can_err_skb(dev, &cf);
  305. if (skb == NULL)
  306. return -ENOMEM;
  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->tx_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. cf->data[6] = txerr;
  387. cf->data[7] = rxerr;
  388. }
  389. priv->can.state = state;
  390. netif_rx(skb);
  391. stats->rx_packets++;
  392. stats->rx_bytes += cf->can_dlc;
  393. return 0;
  394. }
  395. irqreturn_t sja1000_interrupt(int irq, void *dev_id)
  396. {
  397. struct net_device *dev = (struct net_device *)dev_id;
  398. struct sja1000_priv *priv = netdev_priv(dev);
  399. struct net_device_stats *stats = &dev->stats;
  400. uint8_t isrc, status;
  401. int n = 0;
  402. /* Shared interrupts and IRQ off? */
  403. if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
  404. return IRQ_NONE;
  405. if (priv->pre_irq)
  406. priv->pre_irq(priv);
  407. while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
  408. n++;
  409. status = priv->read_reg(priv, REG_SR);
  410. if (isrc & IRQ_WUI)
  411. dev_warn(dev->dev.parent, "wakeup interrupt\n");
  412. if (isrc & IRQ_TI) {
  413. /* transmission complete interrupt */
  414. stats->tx_bytes += priv->read_reg(priv, REG_FI) & 0xf;
  415. stats->tx_packets++;
  416. can_get_echo_skb(dev, 0);
  417. netif_wake_queue(dev);
  418. }
  419. if (isrc & IRQ_RI) {
  420. /* receive interrupt */
  421. while (status & SR_RBS) {
  422. sja1000_rx(dev);
  423. status = priv->read_reg(priv, REG_SR);
  424. }
  425. }
  426. if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
  427. /* error interrupt */
  428. if (sja1000_err(dev, isrc, status))
  429. break;
  430. }
  431. }
  432. if (priv->post_irq)
  433. priv->post_irq(priv);
  434. if (n >= SJA1000_MAX_IRQ)
  435. dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
  436. return (n) ? IRQ_HANDLED : IRQ_NONE;
  437. }
  438. EXPORT_SYMBOL_GPL(sja1000_interrupt);
  439. static int sja1000_open(struct net_device *dev)
  440. {
  441. struct sja1000_priv *priv = netdev_priv(dev);
  442. int err;
  443. /* set chip into reset mode */
  444. set_reset_mode(dev);
  445. /* common open */
  446. err = open_candev(dev);
  447. if (err)
  448. return err;
  449. /* register interrupt handler, if not done by the device driver */
  450. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
  451. err = request_irq(dev->irq, sja1000_interrupt, priv->irq_flags,
  452. dev->name, (void *)dev);
  453. if (err) {
  454. close_candev(dev);
  455. return -EAGAIN;
  456. }
  457. }
  458. /* init and start chi */
  459. sja1000_start(dev);
  460. priv->open_time = jiffies;
  461. netif_start_queue(dev);
  462. return 0;
  463. }
  464. static int sja1000_close(struct net_device *dev)
  465. {
  466. struct sja1000_priv *priv = netdev_priv(dev);
  467. netif_stop_queue(dev);
  468. set_reset_mode(dev);
  469. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER))
  470. free_irq(dev->irq, (void *)dev);
  471. close_candev(dev);
  472. priv->open_time = 0;
  473. return 0;
  474. }
  475. struct net_device *alloc_sja1000dev(int sizeof_priv)
  476. {
  477. struct net_device *dev;
  478. struct sja1000_priv *priv;
  479. dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv,
  480. SJA1000_ECHO_SKB_MAX);
  481. if (!dev)
  482. return NULL;
  483. priv = netdev_priv(dev);
  484. priv->dev = dev;
  485. priv->can.bittiming_const = &sja1000_bittiming_const;
  486. priv->can.do_set_bittiming = sja1000_set_bittiming;
  487. priv->can.do_set_mode = sja1000_set_mode;
  488. priv->can.do_get_berr_counter = sja1000_get_berr_counter;
  489. priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
  490. CAN_CTRLMODE_BERR_REPORTING;
  491. if (sizeof_priv)
  492. priv->priv = (void *)priv + sizeof(struct sja1000_priv);
  493. return dev;
  494. }
  495. EXPORT_SYMBOL_GPL(alloc_sja1000dev);
  496. void free_sja1000dev(struct net_device *dev)
  497. {
  498. free_candev(dev);
  499. }
  500. EXPORT_SYMBOL_GPL(free_sja1000dev);
  501. static const struct net_device_ops sja1000_netdev_ops = {
  502. .ndo_open = sja1000_open,
  503. .ndo_stop = sja1000_close,
  504. .ndo_start_xmit = sja1000_start_xmit,
  505. };
  506. int register_sja1000dev(struct net_device *dev)
  507. {
  508. if (!sja1000_probe_chip(dev))
  509. return -ENODEV;
  510. dev->flags |= IFF_ECHO; /* we support local echo */
  511. dev->netdev_ops = &sja1000_netdev_ops;
  512. set_reset_mode(dev);
  513. chipset_init(dev);
  514. return register_candev(dev);
  515. }
  516. EXPORT_SYMBOL_GPL(register_sja1000dev);
  517. void unregister_sja1000dev(struct net_device *dev)
  518. {
  519. set_reset_mode(dev);
  520. unregister_candev(dev);
  521. }
  522. EXPORT_SYMBOL_GPL(unregister_sja1000dev);
  523. static __init int sja1000_init(void)
  524. {
  525. printk(KERN_INFO "%s CAN netdevice driver\n", DRV_NAME);
  526. return 0;
  527. }
  528. module_init(sja1000_init);
  529. static __exit void sja1000_exit(void)
  530. {
  531. printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
  532. }
  533. module_exit(sja1000_exit);