ti_hecc.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /*
  2. * TI HECC (CAN) device driver
  3. *
  4. * This driver supports TI's HECC (High End CAN Controller module) and the
  5. * specs for the same is available at <http://www.ti.com>
  6. *
  7. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation version 2.
  12. *
  13. * This program is distributed as is WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. /*
  20. * Your platform definitions should specify module ram offsets and interrupt
  21. * number to use as follows:
  22. *
  23. * static struct ti_hecc_platform_data am3517_evm_hecc_pdata = {
  24. * .scc_hecc_offset = 0,
  25. * .scc_ram_offset = 0x3000,
  26. * .hecc_ram_offset = 0x3000,
  27. * .mbx_offset = 0x2000,
  28. * .int_line = 0,
  29. * .revision = 1,
  30. * .transceiver_switch = hecc_phy_control,
  31. * };
  32. *
  33. * Please see include/linux/can/platform/ti_hecc.h for description of
  34. * above fields.
  35. *
  36. */
  37. #include <linux/module.h>
  38. #include <linux/kernel.h>
  39. #include <linux/types.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/errno.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/skbuff.h>
  44. #include <linux/platform_device.h>
  45. #include <linux/clk.h>
  46. #include <linux/io.h>
  47. #include <linux/can/dev.h>
  48. #include <linux/can/error.h>
  49. #include <linux/can/led.h>
  50. #include <linux/can/platform/ti_hecc.h>
  51. #define DRV_NAME "ti_hecc"
  52. #define HECC_MODULE_VERSION "0.7"
  53. MODULE_VERSION(HECC_MODULE_VERSION);
  54. #define DRV_DESC "TI High End CAN Controller Driver " HECC_MODULE_VERSION
  55. /* TX / RX Mailbox Configuration */
  56. #define HECC_MAX_MAILBOXES 32 /* hardware mailboxes - do not change */
  57. #define MAX_TX_PRIO 0x3F /* hardware value - do not change */
  58. /*
  59. * Important Note: TX mailbox configuration
  60. * TX mailboxes should be restricted to the number of SKB buffers to avoid
  61. * maintaining SKB buffers separately. TX mailboxes should be a power of 2
  62. * for the mailbox logic to work. Top mailbox numbers are reserved for RX
  63. * and lower mailboxes for TX.
  64. *
  65. * HECC_MAX_TX_MBOX HECC_MB_TX_SHIFT
  66. * 4 (default) 2
  67. * 8 3
  68. * 16 4
  69. */
  70. #define HECC_MB_TX_SHIFT 2 /* as per table above */
  71. #define HECC_MAX_TX_MBOX BIT(HECC_MB_TX_SHIFT)
  72. #define HECC_TX_PRIO_SHIFT (HECC_MB_TX_SHIFT)
  73. #define HECC_TX_PRIO_MASK (MAX_TX_PRIO << HECC_MB_TX_SHIFT)
  74. #define HECC_TX_MB_MASK (HECC_MAX_TX_MBOX - 1)
  75. #define HECC_TX_MASK ((HECC_MAX_TX_MBOX - 1) | HECC_TX_PRIO_MASK)
  76. #define HECC_TX_MBOX_MASK (~(BIT(HECC_MAX_TX_MBOX) - 1))
  77. #define HECC_DEF_NAPI_WEIGHT HECC_MAX_RX_MBOX
  78. /*
  79. * Important Note: RX mailbox configuration
  80. * RX mailboxes are further logically split into two - main and buffer
  81. * mailboxes. The goal is to get all packets into main mailboxes as
  82. * driven by mailbox number and receive priority (higher to lower) and
  83. * buffer mailboxes are used to receive pkts while main mailboxes are being
  84. * processed. This ensures in-order packet reception.
  85. *
  86. * Here are the recommended values for buffer mailbox. Note that RX mailboxes
  87. * start after TX mailboxes:
  88. *
  89. * HECC_MAX_RX_MBOX HECC_RX_BUFFER_MBOX No of buffer mailboxes
  90. * 28 12 8
  91. * 16 20 4
  92. */
  93. #define HECC_MAX_RX_MBOX (HECC_MAX_MAILBOXES - HECC_MAX_TX_MBOX)
  94. #define HECC_RX_BUFFER_MBOX 12 /* as per table above */
  95. #define HECC_RX_FIRST_MBOX (HECC_MAX_MAILBOXES - 1)
  96. #define HECC_RX_HIGH_MBOX_MASK (~(BIT(HECC_RX_BUFFER_MBOX) - 1))
  97. /* TI HECC module registers */
  98. #define HECC_CANME 0x0 /* Mailbox enable */
  99. #define HECC_CANMD 0x4 /* Mailbox direction */
  100. #define HECC_CANTRS 0x8 /* Transmit request set */
  101. #define HECC_CANTRR 0xC /* Transmit request */
  102. #define HECC_CANTA 0x10 /* Transmission acknowledge */
  103. #define HECC_CANAA 0x14 /* Abort acknowledge */
  104. #define HECC_CANRMP 0x18 /* Receive message pending */
  105. #define HECC_CANRML 0x1C /* Remote message lost */
  106. #define HECC_CANRFP 0x20 /* Remote frame pending */
  107. #define HECC_CANGAM 0x24 /* SECC only:Global acceptance mask */
  108. #define HECC_CANMC 0x28 /* Master control */
  109. #define HECC_CANBTC 0x2C /* Bit timing configuration */
  110. #define HECC_CANES 0x30 /* Error and status */
  111. #define HECC_CANTEC 0x34 /* Transmit error counter */
  112. #define HECC_CANREC 0x38 /* Receive error counter */
  113. #define HECC_CANGIF0 0x3C /* Global interrupt flag 0 */
  114. #define HECC_CANGIM 0x40 /* Global interrupt mask */
  115. #define HECC_CANGIF1 0x44 /* Global interrupt flag 1 */
  116. #define HECC_CANMIM 0x48 /* Mailbox interrupt mask */
  117. #define HECC_CANMIL 0x4C /* Mailbox interrupt level */
  118. #define HECC_CANOPC 0x50 /* Overwrite protection control */
  119. #define HECC_CANTIOC 0x54 /* Transmit I/O control */
  120. #define HECC_CANRIOC 0x58 /* Receive I/O control */
  121. #define HECC_CANLNT 0x5C /* HECC only: Local network time */
  122. #define HECC_CANTOC 0x60 /* HECC only: Time-out control */
  123. #define HECC_CANTOS 0x64 /* HECC only: Time-out status */
  124. #define HECC_CANTIOCE 0x68 /* SCC only:Enhanced TX I/O control */
  125. #define HECC_CANRIOCE 0x6C /* SCC only:Enhanced RX I/O control */
  126. /* Mailbox registers */
  127. #define HECC_CANMID 0x0
  128. #define HECC_CANMCF 0x4
  129. #define HECC_CANMDL 0x8
  130. #define HECC_CANMDH 0xC
  131. #define HECC_SET_REG 0xFFFFFFFF
  132. #define HECC_CANID_MASK 0x3FF /* 18 bits mask for extended id's */
  133. #define HECC_CCE_WAIT_COUNT 100 /* Wait for ~1 sec for CCE bit */
  134. #define HECC_CANMC_SCM BIT(13) /* SCC compat mode */
  135. #define HECC_CANMC_CCR BIT(12) /* Change config request */
  136. #define HECC_CANMC_PDR BIT(11) /* Local Power down - for sleep mode */
  137. #define HECC_CANMC_ABO BIT(7) /* Auto Bus On */
  138. #define HECC_CANMC_STM BIT(6) /* Self test mode - loopback */
  139. #define HECC_CANMC_SRES BIT(5) /* Software reset */
  140. #define HECC_CANTIOC_EN BIT(3) /* Enable CAN TX I/O pin */
  141. #define HECC_CANRIOC_EN BIT(3) /* Enable CAN RX I/O pin */
  142. #define HECC_CANMID_IDE BIT(31) /* Extended frame format */
  143. #define HECC_CANMID_AME BIT(30) /* Acceptance mask enable */
  144. #define HECC_CANMID_AAM BIT(29) /* Auto answer mode */
  145. #define HECC_CANES_FE BIT(24) /* form error */
  146. #define HECC_CANES_BE BIT(23) /* bit error */
  147. #define HECC_CANES_SA1 BIT(22) /* stuck at dominant error */
  148. #define HECC_CANES_CRCE BIT(21) /* CRC error */
  149. #define HECC_CANES_SE BIT(20) /* stuff bit error */
  150. #define HECC_CANES_ACKE BIT(19) /* ack error */
  151. #define HECC_CANES_BO BIT(18) /* Bus off status */
  152. #define HECC_CANES_EP BIT(17) /* Error passive status */
  153. #define HECC_CANES_EW BIT(16) /* Error warning status */
  154. #define HECC_CANES_SMA BIT(5) /* suspend mode ack */
  155. #define HECC_CANES_CCE BIT(4) /* Change config enabled */
  156. #define HECC_CANES_PDA BIT(3) /* Power down mode ack */
  157. #define HECC_CANBTC_SAM BIT(7) /* sample points */
  158. #define HECC_BUS_ERROR (HECC_CANES_FE | HECC_CANES_BE |\
  159. HECC_CANES_CRCE | HECC_CANES_SE |\
  160. HECC_CANES_ACKE)
  161. #define HECC_CANMCF_RTR BIT(4) /* Remote transmit request */
  162. #define HECC_CANGIF_MAIF BIT(17) /* Message alarm interrupt */
  163. #define HECC_CANGIF_TCOIF BIT(16) /* Timer counter overflow int */
  164. #define HECC_CANGIF_GMIF BIT(15) /* Global mailbox interrupt */
  165. #define HECC_CANGIF_AAIF BIT(14) /* Abort ack interrupt */
  166. #define HECC_CANGIF_WDIF BIT(13) /* Write denied interrupt */
  167. #define HECC_CANGIF_WUIF BIT(12) /* Wake up interrupt */
  168. #define HECC_CANGIF_RMLIF BIT(11) /* Receive message lost interrupt */
  169. #define HECC_CANGIF_BOIF BIT(10) /* Bus off interrupt */
  170. #define HECC_CANGIF_EPIF BIT(9) /* Error passive interrupt */
  171. #define HECC_CANGIF_WLIF BIT(8) /* Warning level interrupt */
  172. #define HECC_CANGIF_MBOX_MASK 0x1F /* Mailbox number mask */
  173. #define HECC_CANGIM_I1EN BIT(1) /* Int line 1 enable */
  174. #define HECC_CANGIM_I0EN BIT(0) /* Int line 0 enable */
  175. #define HECC_CANGIM_DEF_MASK 0x700 /* only busoff/warning/passive */
  176. #define HECC_CANGIM_SIL BIT(2) /* system interrupts to int line 1 */
  177. /* CAN Bittiming constants as per HECC specs */
  178. static const struct can_bittiming_const ti_hecc_bittiming_const = {
  179. .name = DRV_NAME,
  180. .tseg1_min = 1,
  181. .tseg1_max = 16,
  182. .tseg2_min = 1,
  183. .tseg2_max = 8,
  184. .sjw_max = 4,
  185. .brp_min = 1,
  186. .brp_max = 256,
  187. .brp_inc = 1,
  188. };
  189. struct ti_hecc_priv {
  190. struct can_priv can; /* MUST be first member/field */
  191. struct napi_struct napi;
  192. struct net_device *ndev;
  193. struct clk *clk;
  194. void __iomem *base;
  195. u32 scc_ram_offset;
  196. u32 hecc_ram_offset;
  197. u32 mbx_offset;
  198. u32 int_line;
  199. spinlock_t mbx_lock; /* CANME register needs protection */
  200. u32 tx_head;
  201. u32 tx_tail;
  202. u32 rx_next;
  203. void (*transceiver_switch)(int);
  204. };
  205. static inline int get_tx_head_mb(struct ti_hecc_priv *priv)
  206. {
  207. return priv->tx_head & HECC_TX_MB_MASK;
  208. }
  209. static inline int get_tx_tail_mb(struct ti_hecc_priv *priv)
  210. {
  211. return priv->tx_tail & HECC_TX_MB_MASK;
  212. }
  213. static inline int get_tx_head_prio(struct ti_hecc_priv *priv)
  214. {
  215. return (priv->tx_head >> HECC_TX_PRIO_SHIFT) & MAX_TX_PRIO;
  216. }
  217. static inline void hecc_write_lam(struct ti_hecc_priv *priv, u32 mbxno, u32 val)
  218. {
  219. __raw_writel(val, priv->base + priv->hecc_ram_offset + mbxno * 4);
  220. }
  221. static inline void hecc_write_mbx(struct ti_hecc_priv *priv, u32 mbxno,
  222. u32 reg, u32 val)
  223. {
  224. __raw_writel(val, priv->base + priv->mbx_offset + mbxno * 0x10 +
  225. reg);
  226. }
  227. static inline u32 hecc_read_mbx(struct ti_hecc_priv *priv, u32 mbxno, u32 reg)
  228. {
  229. return __raw_readl(priv->base + priv->mbx_offset + mbxno * 0x10 +
  230. reg);
  231. }
  232. static inline void hecc_write(struct ti_hecc_priv *priv, u32 reg, u32 val)
  233. {
  234. __raw_writel(val, priv->base + reg);
  235. }
  236. static inline u32 hecc_read(struct ti_hecc_priv *priv, int reg)
  237. {
  238. return __raw_readl(priv->base + reg);
  239. }
  240. static inline void hecc_set_bit(struct ti_hecc_priv *priv, int reg,
  241. u32 bit_mask)
  242. {
  243. hecc_write(priv, reg, hecc_read(priv, reg) | bit_mask);
  244. }
  245. static inline void hecc_clear_bit(struct ti_hecc_priv *priv, int reg,
  246. u32 bit_mask)
  247. {
  248. hecc_write(priv, reg, hecc_read(priv, reg) & ~bit_mask);
  249. }
  250. static inline u32 hecc_get_bit(struct ti_hecc_priv *priv, int reg, u32 bit_mask)
  251. {
  252. return (hecc_read(priv, reg) & bit_mask) ? 1 : 0;
  253. }
  254. static int ti_hecc_set_btc(struct ti_hecc_priv *priv)
  255. {
  256. struct can_bittiming *bit_timing = &priv->can.bittiming;
  257. u32 can_btc;
  258. can_btc = (bit_timing->phase_seg2 - 1) & 0x7;
  259. can_btc |= ((bit_timing->phase_seg1 + bit_timing->prop_seg - 1)
  260. & 0xF) << 3;
  261. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) {
  262. if (bit_timing->brp > 4)
  263. can_btc |= HECC_CANBTC_SAM;
  264. else
  265. netdev_warn(priv->ndev, "WARN: Triple"
  266. "sampling not set due to h/w limitations");
  267. }
  268. can_btc |= ((bit_timing->sjw - 1) & 0x3) << 8;
  269. can_btc |= ((bit_timing->brp - 1) & 0xFF) << 16;
  270. /* ERM being set to 0 by default meaning resync at falling edge */
  271. hecc_write(priv, HECC_CANBTC, can_btc);
  272. netdev_info(priv->ndev, "setting CANBTC=%#x\n", can_btc);
  273. return 0;
  274. }
  275. static void ti_hecc_transceiver_switch(const struct ti_hecc_priv *priv,
  276. int on)
  277. {
  278. if (priv->transceiver_switch)
  279. priv->transceiver_switch(on);
  280. }
  281. static void ti_hecc_reset(struct net_device *ndev)
  282. {
  283. u32 cnt;
  284. struct ti_hecc_priv *priv = netdev_priv(ndev);
  285. netdev_dbg(ndev, "resetting hecc ...\n");
  286. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_SRES);
  287. /* Set change control request and wait till enabled */
  288. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  289. /*
  290. * INFO: It has been observed that at times CCE bit may not be
  291. * set and hw seems to be ok even if this bit is not set so
  292. * timing out with a timing of 1ms to respect the specs
  293. */
  294. cnt = HECC_CCE_WAIT_COUNT;
  295. while (!hecc_get_bit(priv, HECC_CANES, HECC_CANES_CCE) && cnt != 0) {
  296. --cnt;
  297. udelay(10);
  298. }
  299. /*
  300. * Note: On HECC, BTC can be programmed only in initialization mode, so
  301. * it is expected that the can bittiming parameters are set via ip
  302. * utility before the device is opened
  303. */
  304. ti_hecc_set_btc(priv);
  305. /* Clear CCR (and CANMC register) and wait for CCE = 0 enable */
  306. hecc_write(priv, HECC_CANMC, 0);
  307. /*
  308. * INFO: CAN net stack handles bus off and hence disabling auto-bus-on
  309. * hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_ABO);
  310. */
  311. /*
  312. * INFO: It has been observed that at times CCE bit may not be
  313. * set and hw seems to be ok even if this bit is not set so
  314. */
  315. cnt = HECC_CCE_WAIT_COUNT;
  316. while (hecc_get_bit(priv, HECC_CANES, HECC_CANES_CCE) && cnt != 0) {
  317. --cnt;
  318. udelay(10);
  319. }
  320. /* Enable TX and RX I/O Control pins */
  321. hecc_write(priv, HECC_CANTIOC, HECC_CANTIOC_EN);
  322. hecc_write(priv, HECC_CANRIOC, HECC_CANRIOC_EN);
  323. /* Clear registers for clean operation */
  324. hecc_write(priv, HECC_CANTA, HECC_SET_REG);
  325. hecc_write(priv, HECC_CANRMP, HECC_SET_REG);
  326. hecc_write(priv, HECC_CANGIF0, HECC_SET_REG);
  327. hecc_write(priv, HECC_CANGIF1, HECC_SET_REG);
  328. hecc_write(priv, HECC_CANME, 0);
  329. hecc_write(priv, HECC_CANMD, 0);
  330. /* SCC compat mode NOT supported (and not needed too) */
  331. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_SCM);
  332. }
  333. static void ti_hecc_start(struct net_device *ndev)
  334. {
  335. struct ti_hecc_priv *priv = netdev_priv(ndev);
  336. u32 cnt, mbxno, mbx_mask;
  337. /* put HECC in initialization mode and set btc */
  338. ti_hecc_reset(ndev);
  339. priv->tx_head = priv->tx_tail = HECC_TX_MASK;
  340. priv->rx_next = HECC_RX_FIRST_MBOX;
  341. /* Enable local and global acceptance mask registers */
  342. hecc_write(priv, HECC_CANGAM, HECC_SET_REG);
  343. /* Prepare configured mailboxes to receive messages */
  344. for (cnt = 0; cnt < HECC_MAX_RX_MBOX; cnt++) {
  345. mbxno = HECC_MAX_MAILBOXES - 1 - cnt;
  346. mbx_mask = BIT(mbxno);
  347. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  348. hecc_write_mbx(priv, mbxno, HECC_CANMID, HECC_CANMID_AME);
  349. hecc_write_lam(priv, mbxno, HECC_SET_REG);
  350. hecc_set_bit(priv, HECC_CANMD, mbx_mask);
  351. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  352. hecc_set_bit(priv, HECC_CANMIM, mbx_mask);
  353. }
  354. /* Prevent message over-write & Enable interrupts */
  355. hecc_write(priv, HECC_CANOPC, HECC_SET_REG);
  356. if (priv->int_line) {
  357. hecc_write(priv, HECC_CANMIL, HECC_SET_REG);
  358. hecc_write(priv, HECC_CANGIM, HECC_CANGIM_DEF_MASK |
  359. HECC_CANGIM_I1EN | HECC_CANGIM_SIL);
  360. } else {
  361. hecc_write(priv, HECC_CANMIL, 0);
  362. hecc_write(priv, HECC_CANGIM,
  363. HECC_CANGIM_DEF_MASK | HECC_CANGIM_I0EN);
  364. }
  365. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  366. }
  367. static void ti_hecc_stop(struct net_device *ndev)
  368. {
  369. struct ti_hecc_priv *priv = netdev_priv(ndev);
  370. /* Disable interrupts and disable mailboxes */
  371. hecc_write(priv, HECC_CANGIM, 0);
  372. hecc_write(priv, HECC_CANMIM, 0);
  373. hecc_write(priv, HECC_CANME, 0);
  374. priv->can.state = CAN_STATE_STOPPED;
  375. }
  376. static int ti_hecc_do_set_mode(struct net_device *ndev, enum can_mode mode)
  377. {
  378. int ret = 0;
  379. switch (mode) {
  380. case CAN_MODE_START:
  381. ti_hecc_start(ndev);
  382. netif_wake_queue(ndev);
  383. break;
  384. default:
  385. ret = -EOPNOTSUPP;
  386. break;
  387. }
  388. return ret;
  389. }
  390. static int ti_hecc_get_berr_counter(const struct net_device *ndev,
  391. struct can_berr_counter *bec)
  392. {
  393. struct ti_hecc_priv *priv = netdev_priv(ndev);
  394. bec->txerr = hecc_read(priv, HECC_CANTEC);
  395. bec->rxerr = hecc_read(priv, HECC_CANREC);
  396. return 0;
  397. }
  398. /*
  399. * ti_hecc_xmit: HECC Transmit
  400. *
  401. * The transmit mailboxes start from 0 to HECC_MAX_TX_MBOX. In HECC the
  402. * priority of the mailbox for tranmission is dependent upon priority setting
  403. * field in mailbox registers. The mailbox with highest value in priority field
  404. * is transmitted first. Only when two mailboxes have the same value in
  405. * priority field the highest numbered mailbox is transmitted first.
  406. *
  407. * To utilize the HECC priority feature as described above we start with the
  408. * highest numbered mailbox with highest priority level and move on to the next
  409. * mailbox with the same priority level and so on. Once we loop through all the
  410. * transmit mailboxes we choose the next priority level (lower) and so on
  411. * until we reach the lowest priority level on the lowest numbered mailbox
  412. * when we stop transmission until all mailboxes are transmitted and then
  413. * restart at highest numbered mailbox with highest priority.
  414. *
  415. * Two counters (head and tail) are used to track the next mailbox to transmit
  416. * and to track the echo buffer for already transmitted mailbox. The queue
  417. * is stopped when all the mailboxes are busy or when there is a priority
  418. * value roll-over happens.
  419. */
  420. static netdev_tx_t ti_hecc_xmit(struct sk_buff *skb, struct net_device *ndev)
  421. {
  422. struct ti_hecc_priv *priv = netdev_priv(ndev);
  423. struct can_frame *cf = (struct can_frame *)skb->data;
  424. u32 mbxno, mbx_mask, data;
  425. unsigned long flags;
  426. if (can_dropped_invalid_skb(ndev, skb))
  427. return NETDEV_TX_OK;
  428. mbxno = get_tx_head_mb(priv);
  429. mbx_mask = BIT(mbxno);
  430. spin_lock_irqsave(&priv->mbx_lock, flags);
  431. if (unlikely(hecc_read(priv, HECC_CANME) & mbx_mask)) {
  432. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  433. netif_stop_queue(ndev);
  434. netdev_err(priv->ndev,
  435. "BUG: TX mbx not ready tx_head=%08X, tx_tail=%08X\n",
  436. priv->tx_head, priv->tx_tail);
  437. return NETDEV_TX_BUSY;
  438. }
  439. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  440. /* Prepare mailbox for transmission */
  441. data = cf->can_dlc | (get_tx_head_prio(priv) << 8);
  442. if (cf->can_id & CAN_RTR_FLAG) /* Remote transmission request */
  443. data |= HECC_CANMCF_RTR;
  444. hecc_write_mbx(priv, mbxno, HECC_CANMCF, data);
  445. if (cf->can_id & CAN_EFF_FLAG) /* Extended frame format */
  446. data = (cf->can_id & CAN_EFF_MASK) | HECC_CANMID_IDE;
  447. else /* Standard frame format */
  448. data = (cf->can_id & CAN_SFF_MASK) << 18;
  449. hecc_write_mbx(priv, mbxno, HECC_CANMID, data);
  450. hecc_write_mbx(priv, mbxno, HECC_CANMDL,
  451. be32_to_cpu(*(__be32 *)(cf->data)));
  452. if (cf->can_dlc > 4)
  453. hecc_write_mbx(priv, mbxno, HECC_CANMDH,
  454. be32_to_cpu(*(__be32 *)(cf->data + 4)));
  455. else
  456. *(u32 *)(cf->data + 4) = 0;
  457. can_put_echo_skb(skb, ndev, mbxno);
  458. spin_lock_irqsave(&priv->mbx_lock, flags);
  459. --priv->tx_head;
  460. if ((hecc_read(priv, HECC_CANME) & BIT(get_tx_head_mb(priv))) ||
  461. (priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK) {
  462. netif_stop_queue(ndev);
  463. }
  464. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  465. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  466. hecc_clear_bit(priv, HECC_CANMD, mbx_mask);
  467. hecc_set_bit(priv, HECC_CANMIM, mbx_mask);
  468. hecc_write(priv, HECC_CANTRS, mbx_mask);
  469. return NETDEV_TX_OK;
  470. }
  471. static int ti_hecc_rx_pkt(struct ti_hecc_priv *priv, int mbxno)
  472. {
  473. struct net_device_stats *stats = &priv->ndev->stats;
  474. struct can_frame *cf;
  475. struct sk_buff *skb;
  476. u32 data, mbx_mask;
  477. unsigned long flags;
  478. skb = alloc_can_skb(priv->ndev, &cf);
  479. if (!skb) {
  480. if (printk_ratelimit())
  481. netdev_err(priv->ndev,
  482. "ti_hecc_rx_pkt: alloc_can_skb() failed\n");
  483. return -ENOMEM;
  484. }
  485. mbx_mask = BIT(mbxno);
  486. data = hecc_read_mbx(priv, mbxno, HECC_CANMID);
  487. if (data & HECC_CANMID_IDE)
  488. cf->can_id = (data & CAN_EFF_MASK) | CAN_EFF_FLAG;
  489. else
  490. cf->can_id = (data >> 18) & CAN_SFF_MASK;
  491. data = hecc_read_mbx(priv, mbxno, HECC_CANMCF);
  492. if (data & HECC_CANMCF_RTR)
  493. cf->can_id |= CAN_RTR_FLAG;
  494. cf->can_dlc = get_can_dlc(data & 0xF);
  495. data = hecc_read_mbx(priv, mbxno, HECC_CANMDL);
  496. *(__be32 *)(cf->data) = cpu_to_be32(data);
  497. if (cf->can_dlc > 4) {
  498. data = hecc_read_mbx(priv, mbxno, HECC_CANMDH);
  499. *(__be32 *)(cf->data + 4) = cpu_to_be32(data);
  500. }
  501. spin_lock_irqsave(&priv->mbx_lock, flags);
  502. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  503. hecc_write(priv, HECC_CANRMP, mbx_mask);
  504. /* enable mailbox only if it is part of rx buffer mailboxes */
  505. if (priv->rx_next < HECC_RX_BUFFER_MBOX)
  506. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  507. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  508. stats->rx_bytes += cf->can_dlc;
  509. can_led_event(priv->ndev, CAN_LED_EVENT_RX);
  510. netif_receive_skb(skb);
  511. stats->rx_packets++;
  512. return 0;
  513. }
  514. /*
  515. * ti_hecc_rx_poll - HECC receive pkts
  516. *
  517. * The receive mailboxes start from highest numbered mailbox till last xmit
  518. * mailbox. On CAN frame reception the hardware places the data into highest
  519. * numbered mailbox that matches the CAN ID filter. Since all receive mailboxes
  520. * have same filtering (ALL CAN frames) packets will arrive in the highest
  521. * available RX mailbox and we need to ensure in-order packet reception.
  522. *
  523. * To ensure the packets are received in the right order we logically divide
  524. * the RX mailboxes into main and buffer mailboxes. Packets are received as per
  525. * mailbox priotity (higher to lower) in the main bank and once it is full we
  526. * disable further reception into main mailboxes. While the main mailboxes are
  527. * processed in NAPI, further packets are received in buffer mailboxes.
  528. *
  529. * We maintain a RX next mailbox counter to process packets and once all main
  530. * mailboxe packets are passed to the upper stack we enable all of them but
  531. * continue to process packets received in buffer mailboxes. With each packet
  532. * received from buffer mailbox we enable it immediately so as to handle the
  533. * overflow from higher mailboxes.
  534. */
  535. static int ti_hecc_rx_poll(struct napi_struct *napi, int quota)
  536. {
  537. struct net_device *ndev = napi->dev;
  538. struct ti_hecc_priv *priv = netdev_priv(ndev);
  539. u32 num_pkts = 0;
  540. u32 mbx_mask;
  541. unsigned long pending_pkts, flags;
  542. if (!netif_running(ndev))
  543. return 0;
  544. while ((pending_pkts = hecc_read(priv, HECC_CANRMP)) &&
  545. num_pkts < quota) {
  546. mbx_mask = BIT(priv->rx_next); /* next rx mailbox to process */
  547. if (mbx_mask & pending_pkts) {
  548. if (ti_hecc_rx_pkt(priv, priv->rx_next) < 0)
  549. return num_pkts;
  550. ++num_pkts;
  551. } else if (priv->rx_next > HECC_RX_BUFFER_MBOX) {
  552. break; /* pkt not received yet */
  553. }
  554. --priv->rx_next;
  555. if (priv->rx_next == HECC_RX_BUFFER_MBOX) {
  556. /* enable high bank mailboxes */
  557. spin_lock_irqsave(&priv->mbx_lock, flags);
  558. mbx_mask = hecc_read(priv, HECC_CANME);
  559. mbx_mask |= HECC_RX_HIGH_MBOX_MASK;
  560. hecc_write(priv, HECC_CANME, mbx_mask);
  561. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  562. } else if (priv->rx_next == HECC_MAX_TX_MBOX - 1) {
  563. priv->rx_next = HECC_RX_FIRST_MBOX;
  564. break;
  565. }
  566. }
  567. /* Enable packet interrupt if all pkts are handled */
  568. if (hecc_read(priv, HECC_CANRMP) == 0) {
  569. napi_complete(napi);
  570. /* Re-enable RX mailbox interrupts */
  571. mbx_mask = hecc_read(priv, HECC_CANMIM);
  572. mbx_mask |= HECC_TX_MBOX_MASK;
  573. hecc_write(priv, HECC_CANMIM, mbx_mask);
  574. }
  575. return num_pkts;
  576. }
  577. static int ti_hecc_error(struct net_device *ndev, int int_status,
  578. int err_status)
  579. {
  580. struct ti_hecc_priv *priv = netdev_priv(ndev);
  581. struct net_device_stats *stats = &ndev->stats;
  582. struct can_frame *cf;
  583. struct sk_buff *skb;
  584. /* propagate the error condition to the can stack */
  585. skb = alloc_can_err_skb(ndev, &cf);
  586. if (!skb) {
  587. if (printk_ratelimit())
  588. netdev_err(priv->ndev,
  589. "ti_hecc_error: alloc_can_err_skb() failed\n");
  590. return -ENOMEM;
  591. }
  592. if (int_status & HECC_CANGIF_WLIF) { /* warning level int */
  593. if ((int_status & HECC_CANGIF_BOIF) == 0) {
  594. priv->can.state = CAN_STATE_ERROR_WARNING;
  595. ++priv->can.can_stats.error_warning;
  596. cf->can_id |= CAN_ERR_CRTL;
  597. if (hecc_read(priv, HECC_CANTEC) > 96)
  598. cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;
  599. if (hecc_read(priv, HECC_CANREC) > 96)
  600. cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
  601. }
  602. hecc_set_bit(priv, HECC_CANES, HECC_CANES_EW);
  603. netdev_dbg(priv->ndev, "Error Warning interrupt\n");
  604. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  605. }
  606. if (int_status & HECC_CANGIF_EPIF) { /* error passive int */
  607. if ((int_status & HECC_CANGIF_BOIF) == 0) {
  608. priv->can.state = CAN_STATE_ERROR_PASSIVE;
  609. ++priv->can.can_stats.error_passive;
  610. cf->can_id |= CAN_ERR_CRTL;
  611. if (hecc_read(priv, HECC_CANTEC) > 127)
  612. cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
  613. if (hecc_read(priv, HECC_CANREC) > 127)
  614. cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
  615. }
  616. hecc_set_bit(priv, HECC_CANES, HECC_CANES_EP);
  617. netdev_dbg(priv->ndev, "Error passive interrupt\n");
  618. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  619. }
  620. /*
  621. * Need to check busoff condition in error status register too to
  622. * ensure warning interrupts don't hog the system
  623. */
  624. if ((int_status & HECC_CANGIF_BOIF) || (err_status & HECC_CANES_BO)) {
  625. priv->can.state = CAN_STATE_BUS_OFF;
  626. cf->can_id |= CAN_ERR_BUSOFF;
  627. hecc_set_bit(priv, HECC_CANES, HECC_CANES_BO);
  628. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  629. /* Disable all interrupts in bus-off to avoid int hog */
  630. hecc_write(priv, HECC_CANGIM, 0);
  631. ++priv->can.can_stats.bus_off;
  632. can_bus_off(ndev);
  633. }
  634. if (err_status & HECC_BUS_ERROR) {
  635. ++priv->can.can_stats.bus_error;
  636. cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
  637. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  638. if (err_status & HECC_CANES_FE) {
  639. hecc_set_bit(priv, HECC_CANES, HECC_CANES_FE);
  640. cf->data[2] |= CAN_ERR_PROT_FORM;
  641. }
  642. if (err_status & HECC_CANES_BE) {
  643. hecc_set_bit(priv, HECC_CANES, HECC_CANES_BE);
  644. cf->data[2] |= CAN_ERR_PROT_BIT;
  645. }
  646. if (err_status & HECC_CANES_SE) {
  647. hecc_set_bit(priv, HECC_CANES, HECC_CANES_SE);
  648. cf->data[2] |= CAN_ERR_PROT_STUFF;
  649. }
  650. if (err_status & HECC_CANES_CRCE) {
  651. hecc_set_bit(priv, HECC_CANES, HECC_CANES_CRCE);
  652. cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ |
  653. CAN_ERR_PROT_LOC_CRC_DEL;
  654. }
  655. if (err_status & HECC_CANES_ACKE) {
  656. hecc_set_bit(priv, HECC_CANES, HECC_CANES_ACKE);
  657. cf->data[3] |= CAN_ERR_PROT_LOC_ACK |
  658. CAN_ERR_PROT_LOC_ACK_DEL;
  659. }
  660. }
  661. netif_rx(skb);
  662. stats->rx_packets++;
  663. stats->rx_bytes += cf->can_dlc;
  664. return 0;
  665. }
  666. static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)
  667. {
  668. struct net_device *ndev = (struct net_device *)dev_id;
  669. struct ti_hecc_priv *priv = netdev_priv(ndev);
  670. struct net_device_stats *stats = &ndev->stats;
  671. u32 mbxno, mbx_mask, int_status, err_status;
  672. unsigned long ack, flags;
  673. int_status = hecc_read(priv,
  674. (priv->int_line) ? HECC_CANGIF1 : HECC_CANGIF0);
  675. if (!int_status)
  676. return IRQ_NONE;
  677. err_status = hecc_read(priv, HECC_CANES);
  678. if (err_status & (HECC_BUS_ERROR | HECC_CANES_BO |
  679. HECC_CANES_EP | HECC_CANES_EW))
  680. ti_hecc_error(ndev, int_status, err_status);
  681. if (int_status & HECC_CANGIF_GMIF) {
  682. while (priv->tx_tail - priv->tx_head > 0) {
  683. mbxno = get_tx_tail_mb(priv);
  684. mbx_mask = BIT(mbxno);
  685. if (!(mbx_mask & hecc_read(priv, HECC_CANTA)))
  686. break;
  687. hecc_clear_bit(priv, HECC_CANMIM, mbx_mask);
  688. hecc_write(priv, HECC_CANTA, mbx_mask);
  689. spin_lock_irqsave(&priv->mbx_lock, flags);
  690. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  691. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  692. stats->tx_bytes += hecc_read_mbx(priv, mbxno,
  693. HECC_CANMCF) & 0xF;
  694. stats->tx_packets++;
  695. can_led_event(ndev, CAN_LED_EVENT_TX);
  696. can_get_echo_skb(ndev, mbxno);
  697. --priv->tx_tail;
  698. }
  699. /* restart queue if wrap-up or if queue stalled on last pkt */
  700. if (((priv->tx_head == priv->tx_tail) &&
  701. ((priv->tx_head & HECC_TX_MASK) != HECC_TX_MASK)) ||
  702. (((priv->tx_tail & HECC_TX_MASK) == HECC_TX_MASK) &&
  703. ((priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK)))
  704. netif_wake_queue(ndev);
  705. /* Disable RX mailbox interrupts and let NAPI reenable them */
  706. if (hecc_read(priv, HECC_CANRMP)) {
  707. ack = hecc_read(priv, HECC_CANMIM);
  708. ack &= BIT(HECC_MAX_TX_MBOX) - 1;
  709. hecc_write(priv, HECC_CANMIM, ack);
  710. napi_schedule(&priv->napi);
  711. }
  712. }
  713. /* clear all interrupt conditions - read back to avoid spurious ints */
  714. if (priv->int_line) {
  715. hecc_write(priv, HECC_CANGIF1, HECC_SET_REG);
  716. int_status = hecc_read(priv, HECC_CANGIF1);
  717. } else {
  718. hecc_write(priv, HECC_CANGIF0, HECC_SET_REG);
  719. int_status = hecc_read(priv, HECC_CANGIF0);
  720. }
  721. return IRQ_HANDLED;
  722. }
  723. static int ti_hecc_open(struct net_device *ndev)
  724. {
  725. struct ti_hecc_priv *priv = netdev_priv(ndev);
  726. int err;
  727. err = request_irq(ndev->irq, ti_hecc_interrupt, IRQF_SHARED,
  728. ndev->name, ndev);
  729. if (err) {
  730. netdev_err(ndev, "error requesting interrupt\n");
  731. return err;
  732. }
  733. ti_hecc_transceiver_switch(priv, 1);
  734. /* Open common can device */
  735. err = open_candev(ndev);
  736. if (err) {
  737. netdev_err(ndev, "open_candev() failed %d\n", err);
  738. ti_hecc_transceiver_switch(priv, 0);
  739. free_irq(ndev->irq, ndev);
  740. return err;
  741. }
  742. can_led_event(ndev, CAN_LED_EVENT_OPEN);
  743. ti_hecc_start(ndev);
  744. napi_enable(&priv->napi);
  745. netif_start_queue(ndev);
  746. return 0;
  747. }
  748. static int ti_hecc_close(struct net_device *ndev)
  749. {
  750. struct ti_hecc_priv *priv = netdev_priv(ndev);
  751. netif_stop_queue(ndev);
  752. napi_disable(&priv->napi);
  753. ti_hecc_stop(ndev);
  754. free_irq(ndev->irq, ndev);
  755. close_candev(ndev);
  756. ti_hecc_transceiver_switch(priv, 0);
  757. can_led_event(ndev, CAN_LED_EVENT_STOP);
  758. return 0;
  759. }
  760. static const struct net_device_ops ti_hecc_netdev_ops = {
  761. .ndo_open = ti_hecc_open,
  762. .ndo_stop = ti_hecc_close,
  763. .ndo_start_xmit = ti_hecc_xmit,
  764. .ndo_change_mtu = can_change_mtu,
  765. };
  766. static int ti_hecc_probe(struct platform_device *pdev)
  767. {
  768. struct net_device *ndev = (struct net_device *)0;
  769. struct ti_hecc_priv *priv;
  770. struct ti_hecc_platform_data *pdata;
  771. struct resource *mem, *irq;
  772. void __iomem *addr;
  773. int err = -ENODEV;
  774. pdata = dev_get_platdata(&pdev->dev);
  775. if (!pdata) {
  776. dev_err(&pdev->dev, "No platform data\n");
  777. goto probe_exit;
  778. }
  779. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  780. if (!mem) {
  781. dev_err(&pdev->dev, "No mem resources\n");
  782. goto probe_exit;
  783. }
  784. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  785. if (!irq) {
  786. dev_err(&pdev->dev, "No irq resource\n");
  787. goto probe_exit;
  788. }
  789. if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) {
  790. dev_err(&pdev->dev, "HECC region already claimed\n");
  791. err = -EBUSY;
  792. goto probe_exit;
  793. }
  794. addr = ioremap(mem->start, resource_size(mem));
  795. if (!addr) {
  796. dev_err(&pdev->dev, "ioremap failed\n");
  797. err = -ENOMEM;
  798. goto probe_exit_free_region;
  799. }
  800. ndev = alloc_candev(sizeof(struct ti_hecc_priv), HECC_MAX_TX_MBOX);
  801. if (!ndev) {
  802. dev_err(&pdev->dev, "alloc_candev failed\n");
  803. err = -ENOMEM;
  804. goto probe_exit_iounmap;
  805. }
  806. priv = netdev_priv(ndev);
  807. priv->ndev = ndev;
  808. priv->base = addr;
  809. priv->scc_ram_offset = pdata->scc_ram_offset;
  810. priv->hecc_ram_offset = pdata->hecc_ram_offset;
  811. priv->mbx_offset = pdata->mbx_offset;
  812. priv->int_line = pdata->int_line;
  813. priv->transceiver_switch = pdata->transceiver_switch;
  814. priv->can.bittiming_const = &ti_hecc_bittiming_const;
  815. priv->can.do_set_mode = ti_hecc_do_set_mode;
  816. priv->can.do_get_berr_counter = ti_hecc_get_berr_counter;
  817. priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
  818. spin_lock_init(&priv->mbx_lock);
  819. ndev->irq = irq->start;
  820. ndev->flags |= IFF_ECHO;
  821. platform_set_drvdata(pdev, ndev);
  822. SET_NETDEV_DEV(ndev, &pdev->dev);
  823. ndev->netdev_ops = &ti_hecc_netdev_ops;
  824. priv->clk = clk_get(&pdev->dev, "hecc_ck");
  825. if (IS_ERR(priv->clk)) {
  826. dev_err(&pdev->dev, "No clock available\n");
  827. err = PTR_ERR(priv->clk);
  828. priv->clk = NULL;
  829. goto probe_exit_candev;
  830. }
  831. priv->can.clock.freq = clk_get_rate(priv->clk);
  832. netif_napi_add(ndev, &priv->napi, ti_hecc_rx_poll,
  833. HECC_DEF_NAPI_WEIGHT);
  834. clk_enable(priv->clk);
  835. err = register_candev(ndev);
  836. if (err) {
  837. dev_err(&pdev->dev, "register_candev() failed\n");
  838. goto probe_exit_clk;
  839. }
  840. devm_can_led_init(ndev);
  841. dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%u)\n",
  842. priv->base, (u32) ndev->irq);
  843. return 0;
  844. probe_exit_clk:
  845. clk_put(priv->clk);
  846. probe_exit_candev:
  847. free_candev(ndev);
  848. probe_exit_iounmap:
  849. iounmap(addr);
  850. probe_exit_free_region:
  851. release_mem_region(mem->start, resource_size(mem));
  852. probe_exit:
  853. return err;
  854. }
  855. static int ti_hecc_remove(struct platform_device *pdev)
  856. {
  857. struct resource *res;
  858. struct net_device *ndev = platform_get_drvdata(pdev);
  859. struct ti_hecc_priv *priv = netdev_priv(ndev);
  860. unregister_candev(ndev);
  861. clk_disable(priv->clk);
  862. clk_put(priv->clk);
  863. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  864. iounmap(priv->base);
  865. release_mem_region(res->start, resource_size(res));
  866. free_candev(ndev);
  867. return 0;
  868. }
  869. #ifdef CONFIG_PM
  870. static int ti_hecc_suspend(struct platform_device *pdev, pm_message_t state)
  871. {
  872. struct net_device *dev = platform_get_drvdata(pdev);
  873. struct ti_hecc_priv *priv = netdev_priv(dev);
  874. if (netif_running(dev)) {
  875. netif_stop_queue(dev);
  876. netif_device_detach(dev);
  877. }
  878. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  879. priv->can.state = CAN_STATE_SLEEPING;
  880. clk_disable(priv->clk);
  881. return 0;
  882. }
  883. static int ti_hecc_resume(struct platform_device *pdev)
  884. {
  885. struct net_device *dev = platform_get_drvdata(pdev);
  886. struct ti_hecc_priv *priv = netdev_priv(dev);
  887. clk_enable(priv->clk);
  888. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  889. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  890. if (netif_running(dev)) {
  891. netif_device_attach(dev);
  892. netif_start_queue(dev);
  893. }
  894. return 0;
  895. }
  896. #else
  897. #define ti_hecc_suspend NULL
  898. #define ti_hecc_resume NULL
  899. #endif
  900. /* TI HECC netdevice driver: platform driver structure */
  901. static struct platform_driver ti_hecc_driver = {
  902. .driver = {
  903. .name = DRV_NAME,
  904. },
  905. .probe = ti_hecc_probe,
  906. .remove = ti_hecc_remove,
  907. .suspend = ti_hecc_suspend,
  908. .resume = ti_hecc_resume,
  909. };
  910. module_platform_driver(ti_hecc_driver);
  911. MODULE_AUTHOR("Anant Gole <anantgole@ti.com>");
  912. MODULE_LICENSE("GPL v2");
  913. MODULE_DESCRIPTION(DRV_DESC);
  914. MODULE_ALIAS("platform:" DRV_NAME);