ti_hecc.c 32 KB

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