sja1000.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 interrupts */
  119. if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
  120. priv->write_reg(priv, REG_IER, IRQ_ALL);
  121. else
  122. priv->write_reg(priv, REG_IER,
  123. IRQ_ALL & ~IRQ_BEI);
  124. return;
  125. }
  126. /* set chip to normal mode */
  127. priv->write_reg(priv, REG_MOD, 0x00);
  128. udelay(10);
  129. status = priv->read_reg(priv, REG_MOD);
  130. }
  131. dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
  132. }
  133. static void sja1000_start(struct net_device *dev)
  134. {
  135. struct sja1000_priv *priv = netdev_priv(dev);
  136. /* leave reset mode */
  137. if (priv->can.state != CAN_STATE_STOPPED)
  138. set_reset_mode(dev);
  139. /* Clear error counters and error code capture */
  140. priv->write_reg(priv, REG_TXERR, 0x0);
  141. priv->write_reg(priv, REG_RXERR, 0x0);
  142. priv->read_reg(priv, REG_ECC);
  143. /* leave reset mode */
  144. set_normal_mode(dev);
  145. }
  146. static int sja1000_set_mode(struct net_device *dev, enum can_mode mode)
  147. {
  148. struct sja1000_priv *priv = netdev_priv(dev);
  149. if (!priv->open_time)
  150. return -EINVAL;
  151. switch (mode) {
  152. case CAN_MODE_START:
  153. sja1000_start(dev);
  154. if (netif_queue_stopped(dev))
  155. netif_wake_queue(dev);
  156. break;
  157. default:
  158. return -EOPNOTSUPP;
  159. }
  160. return 0;
  161. }
  162. static int sja1000_set_bittiming(struct net_device *dev)
  163. {
  164. struct sja1000_priv *priv = netdev_priv(dev);
  165. struct can_bittiming *bt = &priv->can.bittiming;
  166. u8 btr0, btr1;
  167. btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
  168. btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
  169. (((bt->phase_seg2 - 1) & 0x7) << 4);
  170. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
  171. btr1 |= 0x80;
  172. dev_info(dev->dev.parent,
  173. "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
  174. priv->write_reg(priv, REG_BTR0, btr0);
  175. priv->write_reg(priv, REG_BTR1, btr1);
  176. return 0;
  177. }
  178. static int sja1000_get_berr_counter(const struct net_device *dev,
  179. struct can_berr_counter *bec)
  180. {
  181. struct sja1000_priv *priv = netdev_priv(dev);
  182. bec->txerr = priv->read_reg(priv, REG_TXERR);
  183. bec->rxerr = priv->read_reg(priv, REG_RXERR);
  184. return 0;
  185. }
  186. /*
  187. * initialize SJA1000 chip:
  188. * - reset chip
  189. * - set output mode
  190. * - set baudrate
  191. * - enable interrupts
  192. * - start operating mode
  193. */
  194. static void chipset_init(struct net_device *dev)
  195. {
  196. struct sja1000_priv *priv = netdev_priv(dev);
  197. /* set clock divider and output control register */
  198. priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
  199. /* set acceptance filter (accept all) */
  200. priv->write_reg(priv, REG_ACCC0, 0x00);
  201. priv->write_reg(priv, REG_ACCC1, 0x00);
  202. priv->write_reg(priv, REG_ACCC2, 0x00);
  203. priv->write_reg(priv, REG_ACCC3, 0x00);
  204. priv->write_reg(priv, REG_ACCM0, 0xFF);
  205. priv->write_reg(priv, REG_ACCM1, 0xFF);
  206. priv->write_reg(priv, REG_ACCM2, 0xFF);
  207. priv->write_reg(priv, REG_ACCM3, 0xFF);
  208. priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
  209. }
  210. /*
  211. * transmit a CAN message
  212. * message layout in the sk_buff should be like this:
  213. * xx xx xx xx ff ll 00 11 22 33 44 55 66 77
  214. * [ can-id ] [flags] [len] [can data (up to 8 bytes]
  215. */
  216. static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
  217. struct net_device *dev)
  218. {
  219. struct sja1000_priv *priv = netdev_priv(dev);
  220. struct can_frame *cf = (struct can_frame *)skb->data;
  221. uint8_t fi;
  222. uint8_t dlc;
  223. canid_t id;
  224. uint8_t dreg;
  225. int i;
  226. if (can_dropped_invalid_skb(dev, skb))
  227. return NETDEV_TX_OK;
  228. netif_stop_queue(dev);
  229. fi = dlc = cf->can_dlc;
  230. id = cf->can_id;
  231. if (id & CAN_RTR_FLAG)
  232. fi |= FI_RTR;
  233. if (id & CAN_EFF_FLAG) {
  234. fi |= FI_FF;
  235. dreg = EFF_BUF;
  236. priv->write_reg(priv, REG_FI, fi);
  237. priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
  238. priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
  239. priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
  240. priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
  241. } else {
  242. dreg = SFF_BUF;
  243. priv->write_reg(priv, REG_FI, fi);
  244. priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
  245. priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
  246. }
  247. for (i = 0; i < dlc; i++)
  248. priv->write_reg(priv, dreg++, cf->data[i]);
  249. dev->trans_start = jiffies;
  250. can_put_echo_skb(skb, dev, 0);
  251. priv->write_reg(priv, REG_CMR, CMD_TR);
  252. return NETDEV_TX_OK;
  253. }
  254. static void sja1000_rx(struct net_device *dev)
  255. {
  256. struct sja1000_priv *priv = netdev_priv(dev);
  257. struct net_device_stats *stats = &dev->stats;
  258. struct can_frame *cf;
  259. struct sk_buff *skb;
  260. uint8_t fi;
  261. uint8_t dreg;
  262. canid_t id;
  263. int i;
  264. /* create zero'ed CAN frame buffer */
  265. skb = alloc_can_skb(dev, &cf);
  266. if (skb == NULL)
  267. return;
  268. fi = priv->read_reg(priv, REG_FI);
  269. if (fi & FI_FF) {
  270. /* extended frame format (EFF) */
  271. dreg = EFF_BUF;
  272. id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
  273. | (priv->read_reg(priv, REG_ID2) << (5 + 8))
  274. | (priv->read_reg(priv, REG_ID3) << 5)
  275. | (priv->read_reg(priv, REG_ID4) >> 3);
  276. id |= CAN_EFF_FLAG;
  277. } else {
  278. /* standard frame format (SFF) */
  279. dreg = SFF_BUF;
  280. id = (priv->read_reg(priv, REG_ID1) << 3)
  281. | (priv->read_reg(priv, REG_ID2) >> 5);
  282. }
  283. if (fi & FI_RTR) {
  284. id |= CAN_RTR_FLAG;
  285. } else {
  286. cf->can_dlc = get_can_dlc(fi & 0x0F);
  287. for (i = 0; i < cf->can_dlc; i++)
  288. cf->data[i] = priv->read_reg(priv, dreg++);
  289. }
  290. cf->can_id = id;
  291. /* release receive buffer */
  292. priv->write_reg(priv, REG_CMR, CMD_RRB);
  293. netif_rx(skb);
  294. stats->rx_packets++;
  295. stats->rx_bytes += cf->can_dlc;
  296. }
  297. static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
  298. {
  299. struct sja1000_priv *priv = netdev_priv(dev);
  300. struct net_device_stats *stats = &dev->stats;
  301. struct can_frame *cf;
  302. struct sk_buff *skb;
  303. enum can_state state = priv->can.state;
  304. uint8_t ecc, alc;
  305. skb = alloc_can_err_skb(dev, &cf);
  306. if (skb == NULL)
  307. return -ENOMEM;
  308. if (isrc & IRQ_DOI) {
  309. /* data overrun interrupt */
  310. dev_dbg(dev->dev.parent, "data overrun interrupt\n");
  311. cf->can_id |= CAN_ERR_CRTL;
  312. cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
  313. stats->rx_over_errors++;
  314. stats->rx_errors++;
  315. priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
  316. }
  317. if (isrc & IRQ_EI) {
  318. /* error warning interrupt */
  319. dev_dbg(dev->dev.parent, "error warning interrupt\n");
  320. if (status & SR_BS) {
  321. state = CAN_STATE_BUS_OFF;
  322. cf->can_id |= CAN_ERR_BUSOFF;
  323. can_bus_off(dev);
  324. } else if (status & SR_ES) {
  325. state = CAN_STATE_ERROR_WARNING;
  326. } else
  327. state = CAN_STATE_ERROR_ACTIVE;
  328. }
  329. if (isrc & IRQ_BEI) {
  330. /* bus error interrupt */
  331. priv->can.can_stats.bus_error++;
  332. stats->rx_errors++;
  333. ecc = priv->read_reg(priv, REG_ECC);
  334. cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
  335. switch (ecc & ECC_MASK) {
  336. case ECC_BIT:
  337. cf->data[2] |= CAN_ERR_PROT_BIT;
  338. break;
  339. case ECC_FORM:
  340. cf->data[2] |= CAN_ERR_PROT_FORM;
  341. break;
  342. case ECC_STUFF:
  343. cf->data[2] |= CAN_ERR_PROT_STUFF;
  344. break;
  345. default:
  346. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  347. cf->data[3] = ecc & ECC_SEG;
  348. break;
  349. }
  350. /* Error occured during transmission? */
  351. if ((ecc & ECC_DIR) == 0)
  352. cf->data[2] |= CAN_ERR_PROT_TX;
  353. }
  354. if (isrc & IRQ_EPI) {
  355. /* error passive interrupt */
  356. dev_dbg(dev->dev.parent, "error passive interrupt\n");
  357. if (status & SR_ES)
  358. state = CAN_STATE_ERROR_PASSIVE;
  359. else
  360. state = CAN_STATE_ERROR_ACTIVE;
  361. }
  362. if (isrc & IRQ_ALI) {
  363. /* arbitration lost interrupt */
  364. dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
  365. alc = priv->read_reg(priv, REG_ALC);
  366. priv->can.can_stats.arbitration_lost++;
  367. stats->tx_errors++;
  368. cf->can_id |= CAN_ERR_LOSTARB;
  369. cf->data[0] = alc & 0x1f;
  370. }
  371. if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
  372. state == CAN_STATE_ERROR_PASSIVE)) {
  373. uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
  374. uint8_t txerr = priv->read_reg(priv, REG_TXERR);
  375. cf->can_id |= CAN_ERR_CRTL;
  376. if (state == CAN_STATE_ERROR_WARNING) {
  377. priv->can.can_stats.error_warning++;
  378. cf->data[1] = (txerr > rxerr) ?
  379. CAN_ERR_CRTL_TX_WARNING :
  380. CAN_ERR_CRTL_RX_WARNING;
  381. } else {
  382. priv->can.can_stats.error_passive++;
  383. cf->data[1] = (txerr > rxerr) ?
  384. CAN_ERR_CRTL_TX_PASSIVE :
  385. CAN_ERR_CRTL_RX_PASSIVE;
  386. }
  387. cf->data[6] = txerr;
  388. cf->data[7] = rxerr;
  389. }
  390. priv->can.state = state;
  391. netif_rx(skb);
  392. stats->rx_packets++;
  393. stats->rx_bytes += cf->can_dlc;
  394. return 0;
  395. }
  396. irqreturn_t sja1000_interrupt(int irq, void *dev_id)
  397. {
  398. struct net_device *dev = (struct net_device *)dev_id;
  399. struct sja1000_priv *priv = netdev_priv(dev);
  400. struct net_device_stats *stats = &dev->stats;
  401. uint8_t isrc, status;
  402. int n = 0;
  403. /* Shared interrupts and IRQ off? */
  404. if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
  405. return IRQ_NONE;
  406. if (priv->pre_irq)
  407. priv->pre_irq(priv);
  408. while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
  409. n++;
  410. status = priv->read_reg(priv, REG_SR);
  411. if (isrc & IRQ_WUI)
  412. dev_warn(dev->dev.parent, "wakeup interrupt\n");
  413. if (isrc & IRQ_TI) {
  414. /* transmission complete interrupt */
  415. stats->tx_bytes += priv->read_reg(priv, REG_FI) & 0xf;
  416. stats->tx_packets++;
  417. can_get_echo_skb(dev, 0);
  418. netif_wake_queue(dev);
  419. }
  420. if (isrc & IRQ_RI) {
  421. /* receive interrupt */
  422. while (status & SR_RBS) {
  423. sja1000_rx(dev);
  424. status = priv->read_reg(priv, REG_SR);
  425. }
  426. }
  427. if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
  428. /* error interrupt */
  429. if (sja1000_err(dev, isrc, status))
  430. break;
  431. }
  432. }
  433. if (priv->post_irq)
  434. priv->post_irq(priv);
  435. if (n >= SJA1000_MAX_IRQ)
  436. dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
  437. return (n) ? IRQ_HANDLED : IRQ_NONE;
  438. }
  439. EXPORT_SYMBOL_GPL(sja1000_interrupt);
  440. static int sja1000_open(struct net_device *dev)
  441. {
  442. struct sja1000_priv *priv = netdev_priv(dev);
  443. int err;
  444. /* set chip into reset mode */
  445. set_reset_mode(dev);
  446. /* common open */
  447. err = open_candev(dev);
  448. if (err)
  449. return err;
  450. /* register interrupt handler, if not done by the device driver */
  451. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
  452. err = request_irq(dev->irq, sja1000_interrupt, priv->irq_flags,
  453. dev->name, (void *)dev);
  454. if (err) {
  455. close_candev(dev);
  456. return -EAGAIN;
  457. }
  458. }
  459. /* init and start chi */
  460. sja1000_start(dev);
  461. priv->open_time = jiffies;
  462. netif_start_queue(dev);
  463. return 0;
  464. }
  465. static int sja1000_close(struct net_device *dev)
  466. {
  467. struct sja1000_priv *priv = netdev_priv(dev);
  468. netif_stop_queue(dev);
  469. set_reset_mode(dev);
  470. if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER))
  471. free_irq(dev->irq, (void *)dev);
  472. close_candev(dev);
  473. priv->open_time = 0;
  474. return 0;
  475. }
  476. struct net_device *alloc_sja1000dev(int sizeof_priv)
  477. {
  478. struct net_device *dev;
  479. struct sja1000_priv *priv;
  480. dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv,
  481. SJA1000_ECHO_SKB_MAX);
  482. if (!dev)
  483. return NULL;
  484. priv = netdev_priv(dev);
  485. priv->dev = dev;
  486. priv->can.bittiming_const = &sja1000_bittiming_const;
  487. priv->can.do_set_bittiming = sja1000_set_bittiming;
  488. priv->can.do_set_mode = sja1000_set_mode;
  489. priv->can.do_get_berr_counter = sja1000_get_berr_counter;
  490. priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
  491. CAN_CTRLMODE_BERR_REPORTING;
  492. if (sizeof_priv)
  493. priv->priv = (void *)priv + sizeof(struct sja1000_priv);
  494. return dev;
  495. }
  496. EXPORT_SYMBOL_GPL(alloc_sja1000dev);
  497. void free_sja1000dev(struct net_device *dev)
  498. {
  499. free_candev(dev);
  500. }
  501. EXPORT_SYMBOL_GPL(free_sja1000dev);
  502. static const struct net_device_ops sja1000_netdev_ops = {
  503. .ndo_open = sja1000_open,
  504. .ndo_stop = sja1000_close,
  505. .ndo_start_xmit = sja1000_start_xmit,
  506. };
  507. int register_sja1000dev(struct net_device *dev)
  508. {
  509. if (!sja1000_probe_chip(dev))
  510. return -ENODEV;
  511. dev->flags |= IFF_ECHO; /* we support local echo */
  512. dev->netdev_ops = &sja1000_netdev_ops;
  513. set_reset_mode(dev);
  514. chipset_init(dev);
  515. return register_candev(dev);
  516. }
  517. EXPORT_SYMBOL_GPL(register_sja1000dev);
  518. void unregister_sja1000dev(struct net_device *dev)
  519. {
  520. set_reset_mode(dev);
  521. unregister_candev(dev);
  522. }
  523. EXPORT_SYMBOL_GPL(unregister_sja1000dev);
  524. static __init int sja1000_init(void)
  525. {
  526. printk(KERN_INFO "%s CAN netdevice driver\n", DRV_NAME);
  527. return 0;
  528. }
  529. module_init(sja1000_init);
  530. static __exit void sja1000_exit(void)
  531. {
  532. printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
  533. }
  534. module_exit(sja1000_exit);