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/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 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_get_state(const struct net_device *ndev,
  255. enum can_state *state)
  256. {
  257. struct ti_hecc_priv *priv = netdev_priv(ndev);
  258. *state = priv->can.state;
  259. return 0;
  260. }
  261. static int ti_hecc_set_btc(struct ti_hecc_priv *priv)
  262. {
  263. struct can_bittiming *bit_timing = &priv->can.bittiming;
  264. u32 can_btc;
  265. can_btc = (bit_timing->phase_seg2 - 1) & 0x7;
  266. can_btc |= ((bit_timing->phase_seg1 + bit_timing->prop_seg - 1)
  267. & 0xF) << 3;
  268. if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) {
  269. if (bit_timing->brp > 4)
  270. can_btc |= HECC_CANBTC_SAM;
  271. else
  272. dev_warn(priv->ndev->dev.parent, "WARN: Triple" \
  273. "sampling not set due to h/w limitations");
  274. }
  275. can_btc |= ((bit_timing->sjw - 1) & 0x3) << 8;
  276. can_btc |= ((bit_timing->brp - 1) & 0xFF) << 16;
  277. /* ERM being set to 0 by default meaning resync at falling edge */
  278. hecc_write(priv, HECC_CANBTC, can_btc);
  279. dev_info(priv->ndev->dev.parent, "setting CANBTC=%#x\n", can_btc);
  280. return 0;
  281. }
  282. static void ti_hecc_transceiver_switch(const struct ti_hecc_priv *priv,
  283. int on)
  284. {
  285. if (priv->transceiver_switch)
  286. priv->transceiver_switch(on);
  287. }
  288. static void ti_hecc_reset(struct net_device *ndev)
  289. {
  290. u32 cnt;
  291. struct ti_hecc_priv *priv = netdev_priv(ndev);
  292. dev_dbg(ndev->dev.parent, "resetting hecc ...\n");
  293. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_SRES);
  294. /* Set change control request and wait till enabled */
  295. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  296. /*
  297. * INFO: It has been observed that at times CCE bit may not be
  298. * set and hw seems to be ok even if this bit is not set so
  299. * timing out with a timing of 1ms to respect the specs
  300. */
  301. cnt = HECC_CCE_WAIT_COUNT;
  302. while (!hecc_get_bit(priv, HECC_CANES, HECC_CANES_CCE) && cnt != 0) {
  303. --cnt;
  304. udelay(10);
  305. }
  306. /*
  307. * Note: On HECC, BTC can be programmed only in initialization mode, so
  308. * it is expected that the can bittiming parameters are set via ip
  309. * utility before the device is opened
  310. */
  311. ti_hecc_set_btc(priv);
  312. /* Clear CCR (and CANMC register) and wait for CCE = 0 enable */
  313. hecc_write(priv, HECC_CANMC, 0);
  314. /*
  315. * INFO: CAN net stack handles bus off and hence disabling auto-bus-on
  316. * hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_ABO);
  317. */
  318. /*
  319. * INFO: It has been observed that at times CCE bit may not be
  320. * set and hw seems to be ok even if this bit is not set so
  321. */
  322. cnt = HECC_CCE_WAIT_COUNT;
  323. while (hecc_get_bit(priv, HECC_CANES, HECC_CANES_CCE) && cnt != 0) {
  324. --cnt;
  325. udelay(10);
  326. }
  327. /* Enable TX and RX I/O Control pins */
  328. hecc_write(priv, HECC_CANTIOC, HECC_CANTIOC_EN);
  329. hecc_write(priv, HECC_CANRIOC, HECC_CANRIOC_EN);
  330. /* Clear registers for clean operation */
  331. hecc_write(priv, HECC_CANTA, HECC_SET_REG);
  332. hecc_write(priv, HECC_CANRMP, HECC_SET_REG);
  333. hecc_write(priv, HECC_CANGIF0, HECC_SET_REG);
  334. hecc_write(priv, HECC_CANGIF1, HECC_SET_REG);
  335. hecc_write(priv, HECC_CANME, 0);
  336. hecc_write(priv, HECC_CANMD, 0);
  337. /* SCC compat mode NOT supported (and not needed too) */
  338. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_SCM);
  339. }
  340. static void ti_hecc_start(struct net_device *ndev)
  341. {
  342. struct ti_hecc_priv *priv = netdev_priv(ndev);
  343. u32 cnt, mbxno, mbx_mask;
  344. /* put HECC in initialization mode and set btc */
  345. ti_hecc_reset(ndev);
  346. priv->tx_head = priv->tx_tail = HECC_TX_MASK;
  347. priv->rx_next = HECC_RX_FIRST_MBOX;
  348. /* Enable local and global acceptance mask registers */
  349. hecc_write(priv, HECC_CANGAM, HECC_SET_REG);
  350. /* Prepare configured mailboxes to receive messages */
  351. for (cnt = 0; cnt < HECC_MAX_RX_MBOX; cnt++) {
  352. mbxno = HECC_MAX_MAILBOXES - 1 - cnt;
  353. mbx_mask = BIT(mbxno);
  354. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  355. hecc_write_mbx(priv, mbxno, HECC_CANMID, HECC_CANMID_AME);
  356. hecc_write_lam(priv, mbxno, HECC_SET_REG);
  357. hecc_set_bit(priv, HECC_CANMD, mbx_mask);
  358. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  359. hecc_set_bit(priv, HECC_CANMIM, mbx_mask);
  360. }
  361. /* Prevent message over-write & Enable interrupts */
  362. hecc_write(priv, HECC_CANOPC, HECC_SET_REG);
  363. if (priv->int_line) {
  364. hecc_write(priv, HECC_CANMIL, HECC_SET_REG);
  365. hecc_write(priv, HECC_CANGIM, HECC_CANGIM_DEF_MASK |
  366. HECC_CANGIM_I1EN | HECC_CANGIM_SIL);
  367. } else {
  368. hecc_write(priv, HECC_CANMIL, 0);
  369. hecc_write(priv, HECC_CANGIM,
  370. HECC_CANGIM_DEF_MASK | HECC_CANGIM_I0EN);
  371. }
  372. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  373. }
  374. static void ti_hecc_stop(struct net_device *ndev)
  375. {
  376. struct ti_hecc_priv *priv = netdev_priv(ndev);
  377. /* Disable interrupts and disable mailboxes */
  378. hecc_write(priv, HECC_CANGIM, 0);
  379. hecc_write(priv, HECC_CANMIM, 0);
  380. hecc_write(priv, HECC_CANME, 0);
  381. priv->can.state = CAN_STATE_STOPPED;
  382. }
  383. static int ti_hecc_do_set_mode(struct net_device *ndev, enum can_mode mode)
  384. {
  385. int ret = 0;
  386. switch (mode) {
  387. case CAN_MODE_START:
  388. ti_hecc_start(ndev);
  389. netif_wake_queue(ndev);
  390. break;
  391. default:
  392. ret = -EOPNOTSUPP;
  393. break;
  394. }
  395. return ret;
  396. }
  397. /*
  398. * ti_hecc_xmit: HECC Transmit
  399. *
  400. * The transmit mailboxes start from 0 to HECC_MAX_TX_MBOX. In HECC the
  401. * priority of the mailbox for tranmission is dependent upon priority setting
  402. * field in mailbox registers. The mailbox with highest value in priority field
  403. * is transmitted first. Only when two mailboxes have the same value in
  404. * priority field the highest numbered mailbox is transmitted first.
  405. *
  406. * To utilize the HECC priority feature as described above we start with the
  407. * highest numbered mailbox with highest priority level and move on to the next
  408. * mailbox with the same priority level and so on. Once we loop through all the
  409. * transmit mailboxes we choose the next priority level (lower) and so on
  410. * until we reach the lowest priority level on the lowest numbered mailbox
  411. * when we stop transmission until all mailboxes are transmitted and then
  412. * restart at highest numbered mailbox with highest priority.
  413. *
  414. * Two counters (head and tail) are used to track the next mailbox to transmit
  415. * and to track the echo buffer for already transmitted mailbox. The queue
  416. * is stopped when all the mailboxes are busy or when there is a priority
  417. * value roll-over happens.
  418. */
  419. static netdev_tx_t ti_hecc_xmit(struct sk_buff *skb, struct net_device *ndev)
  420. {
  421. struct ti_hecc_priv *priv = netdev_priv(ndev);
  422. struct can_frame *cf = (struct can_frame *)skb->data;
  423. u32 mbxno, mbx_mask, data;
  424. unsigned long flags;
  425. if (can_dropped_invalid_skb(ndev, skb))
  426. return NETDEV_TX_OK;
  427. mbxno = get_tx_head_mb(priv);
  428. mbx_mask = BIT(mbxno);
  429. spin_lock_irqsave(&priv->mbx_lock, flags);
  430. if (unlikely(hecc_read(priv, HECC_CANME) & mbx_mask)) {
  431. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  432. netif_stop_queue(ndev);
  433. dev_err(priv->ndev->dev.parent,
  434. "BUG: TX mbx not ready tx_head=%08X, tx_tail=%08X\n",
  435. priv->tx_head, priv->tx_tail);
  436. return NETDEV_TX_BUSY;
  437. }
  438. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  439. /* Prepare mailbox for transmission */
  440. data = cf->can_dlc | (get_tx_head_prio(priv) << 8);
  441. if (cf->can_id & CAN_RTR_FLAG) /* Remote transmission request */
  442. data |= HECC_CANMCF_RTR;
  443. hecc_write_mbx(priv, mbxno, HECC_CANMCF, data);
  444. if (cf->can_id & CAN_EFF_FLAG) /* Extended frame format */
  445. data = (cf->can_id & CAN_EFF_MASK) | HECC_CANMID_IDE;
  446. else /* Standard frame format */
  447. data = (cf->can_id & CAN_SFF_MASK) << 18;
  448. hecc_write_mbx(priv, mbxno, HECC_CANMID, data);
  449. hecc_write_mbx(priv, mbxno, HECC_CANMDL,
  450. be32_to_cpu(*(u32 *)(cf->data)));
  451. if (cf->can_dlc > 4)
  452. hecc_write_mbx(priv, mbxno, HECC_CANMDH,
  453. be32_to_cpu(*(u32 *)(cf->data + 4)));
  454. else
  455. *(u32 *)(cf->data + 4) = 0;
  456. can_put_echo_skb(skb, ndev, mbxno);
  457. spin_lock_irqsave(&priv->mbx_lock, flags);
  458. --priv->tx_head;
  459. if ((hecc_read(priv, HECC_CANME) & BIT(get_tx_head_mb(priv))) ||
  460. (priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK) {
  461. netif_stop_queue(ndev);
  462. }
  463. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  464. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  465. hecc_clear_bit(priv, HECC_CANMD, mbx_mask);
  466. hecc_set_bit(priv, HECC_CANMIM, mbx_mask);
  467. hecc_write(priv, HECC_CANTRS, mbx_mask);
  468. return NETDEV_TX_OK;
  469. }
  470. static int ti_hecc_rx_pkt(struct ti_hecc_priv *priv, int mbxno)
  471. {
  472. struct net_device_stats *stats = &priv->ndev->stats;
  473. struct can_frame *cf;
  474. struct sk_buff *skb;
  475. u32 data, mbx_mask;
  476. unsigned long flags;
  477. skb = alloc_can_skb(priv->ndev, &cf);
  478. if (!skb) {
  479. if (printk_ratelimit())
  480. dev_err(priv->ndev->dev.parent,
  481. "ti_hecc_rx_pkt: alloc_can_skb() failed\n");
  482. return -ENOMEM;
  483. }
  484. mbx_mask = BIT(mbxno);
  485. data = hecc_read_mbx(priv, mbxno, HECC_CANMID);
  486. if (data & HECC_CANMID_IDE)
  487. cf->can_id = (data & CAN_EFF_MASK) | CAN_EFF_FLAG;
  488. else
  489. cf->can_id = (data >> 18) & CAN_SFF_MASK;
  490. data = hecc_read_mbx(priv, mbxno, HECC_CANMCF);
  491. if (data & HECC_CANMCF_RTR)
  492. cf->can_id |= CAN_RTR_FLAG;
  493. cf->can_dlc = get_can_dlc(data & 0xF);
  494. data = hecc_read_mbx(priv, mbxno, HECC_CANMDL);
  495. *(u32 *)(cf->data) = cpu_to_be32(data);
  496. if (cf->can_dlc > 4) {
  497. data = hecc_read_mbx(priv, mbxno, HECC_CANMDH);
  498. *(u32 *)(cf->data + 4) = cpu_to_be32(data);
  499. } else {
  500. *(u32 *)(cf->data + 4) = 0;
  501. }
  502. spin_lock_irqsave(&priv->mbx_lock, flags);
  503. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  504. hecc_write(priv, HECC_CANRMP, mbx_mask);
  505. /* enable mailbox only if it is part of rx buffer mailboxes */
  506. if (priv->rx_next < HECC_RX_BUFFER_MBOX)
  507. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  508. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  509. stats->rx_bytes += cf->can_dlc;
  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. dev_err(priv->ndev->dev.parent,
  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. dev_dbg(priv->ndev->dev.parent, "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. dev_dbg(priv->ndev->dev.parent, "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. can_bus_off(ndev);
  632. }
  633. if (err_status & HECC_BUS_ERROR) {
  634. ++priv->can.can_stats.bus_error;
  635. cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
  636. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  637. if (err_status & HECC_CANES_FE) {
  638. hecc_set_bit(priv, HECC_CANES, HECC_CANES_FE);
  639. cf->data[2] |= CAN_ERR_PROT_FORM;
  640. }
  641. if (err_status & HECC_CANES_BE) {
  642. hecc_set_bit(priv, HECC_CANES, HECC_CANES_BE);
  643. cf->data[2] |= CAN_ERR_PROT_BIT;
  644. }
  645. if (err_status & HECC_CANES_SE) {
  646. hecc_set_bit(priv, HECC_CANES, HECC_CANES_SE);
  647. cf->data[2] |= CAN_ERR_PROT_STUFF;
  648. }
  649. if (err_status & HECC_CANES_CRCE) {
  650. hecc_set_bit(priv, HECC_CANES, HECC_CANES_CRCE);
  651. cf->data[2] |= CAN_ERR_PROT_LOC_CRC_SEQ |
  652. CAN_ERR_PROT_LOC_CRC_DEL;
  653. }
  654. if (err_status & HECC_CANES_ACKE) {
  655. hecc_set_bit(priv, HECC_CANES, HECC_CANES_ACKE);
  656. cf->data[2] |= CAN_ERR_PROT_LOC_ACK |
  657. CAN_ERR_PROT_LOC_ACK_DEL;
  658. }
  659. }
  660. netif_receive_skb(skb);
  661. stats->rx_packets++;
  662. stats->rx_bytes += cf->can_dlc;
  663. return 0;
  664. }
  665. static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)
  666. {
  667. struct net_device *ndev = (struct net_device *)dev_id;
  668. struct ti_hecc_priv *priv = netdev_priv(ndev);
  669. struct net_device_stats *stats = &ndev->stats;
  670. u32 mbxno, mbx_mask, int_status, err_status;
  671. unsigned long ack, flags;
  672. int_status = hecc_read(priv,
  673. (priv->int_line) ? HECC_CANGIF1 : HECC_CANGIF0);
  674. if (!int_status)
  675. return IRQ_NONE;
  676. err_status = hecc_read(priv, HECC_CANES);
  677. if (err_status & (HECC_BUS_ERROR | HECC_CANES_BO |
  678. HECC_CANES_EP | HECC_CANES_EW))
  679. ti_hecc_error(ndev, int_status, err_status);
  680. if (int_status & HECC_CANGIF_GMIF) {
  681. while (priv->tx_tail - priv->tx_head > 0) {
  682. mbxno = get_tx_tail_mb(priv);
  683. mbx_mask = BIT(mbxno);
  684. if (!(mbx_mask & hecc_read(priv, HECC_CANTA)))
  685. break;
  686. hecc_clear_bit(priv, HECC_CANMIM, mbx_mask);
  687. hecc_write(priv, HECC_CANTA, mbx_mask);
  688. spin_lock_irqsave(&priv->mbx_lock, flags);
  689. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  690. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  691. stats->tx_bytes += hecc_read_mbx(priv, mbxno,
  692. HECC_CANMCF) & 0xF;
  693. stats->tx_packets++;
  694. can_get_echo_skb(ndev, mbxno);
  695. --priv->tx_tail;
  696. }
  697. /* restart queue if wrap-up or if queue stalled on last pkt */
  698. if (((priv->tx_head == priv->tx_tail) &&
  699. ((priv->tx_head & HECC_TX_MASK) != HECC_TX_MASK)) ||
  700. (((priv->tx_tail & HECC_TX_MASK) == HECC_TX_MASK) &&
  701. ((priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK)))
  702. netif_wake_queue(ndev);
  703. /* Disable RX mailbox interrupts and let NAPI reenable them */
  704. if (hecc_read(priv, HECC_CANRMP)) {
  705. ack = hecc_read(priv, HECC_CANMIM);
  706. ack &= BIT(HECC_MAX_TX_MBOX) - 1;
  707. hecc_write(priv, HECC_CANMIM, ack);
  708. napi_schedule(&priv->napi);
  709. }
  710. }
  711. /* clear all interrupt conditions - read back to avoid spurious ints */
  712. if (priv->int_line) {
  713. hecc_write(priv, HECC_CANGIF1, HECC_SET_REG);
  714. int_status = hecc_read(priv, HECC_CANGIF1);
  715. } else {
  716. hecc_write(priv, HECC_CANGIF0, HECC_SET_REG);
  717. int_status = hecc_read(priv, HECC_CANGIF0);
  718. }
  719. return IRQ_HANDLED;
  720. }
  721. static int ti_hecc_open(struct net_device *ndev)
  722. {
  723. struct ti_hecc_priv *priv = netdev_priv(ndev);
  724. int err;
  725. err = request_irq(ndev->irq, ti_hecc_interrupt, IRQF_SHARED,
  726. ndev->name, ndev);
  727. if (err) {
  728. dev_err(ndev->dev.parent, "error requesting interrupt\n");
  729. return err;
  730. }
  731. ti_hecc_transceiver_switch(priv, 1);
  732. /* Open common can device */
  733. err = open_candev(ndev);
  734. if (err) {
  735. dev_err(ndev->dev.parent, "open_candev() failed %d\n", err);
  736. ti_hecc_transceiver_switch(priv, 0);
  737. free_irq(ndev->irq, ndev);
  738. return err;
  739. }
  740. ti_hecc_start(ndev);
  741. napi_enable(&priv->napi);
  742. netif_start_queue(ndev);
  743. return 0;
  744. }
  745. static int ti_hecc_close(struct net_device *ndev)
  746. {
  747. struct ti_hecc_priv *priv = netdev_priv(ndev);
  748. netif_stop_queue(ndev);
  749. napi_disable(&priv->napi);
  750. ti_hecc_stop(ndev);
  751. free_irq(ndev->irq, ndev);
  752. close_candev(ndev);
  753. ti_hecc_transceiver_switch(priv, 0);
  754. return 0;
  755. }
  756. static const struct net_device_ops ti_hecc_netdev_ops = {
  757. .ndo_open = ti_hecc_open,
  758. .ndo_stop = ti_hecc_close,
  759. .ndo_start_xmit = ti_hecc_xmit,
  760. };
  761. static int ti_hecc_probe(struct platform_device *pdev)
  762. {
  763. struct net_device *ndev = (struct net_device *)0;
  764. struct ti_hecc_priv *priv;
  765. struct ti_hecc_platform_data *pdata;
  766. struct resource *mem, *irq;
  767. void __iomem *addr;
  768. int err = -ENODEV;
  769. pdata = pdev->dev.platform_data;
  770. if (!pdata) {
  771. dev_err(&pdev->dev, "No platform data\n");
  772. goto probe_exit;
  773. }
  774. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  775. if (!mem) {
  776. dev_err(&pdev->dev, "No mem resources\n");
  777. goto probe_exit;
  778. }
  779. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  780. if (!irq) {
  781. dev_err(&pdev->dev, "No irq resource\n");
  782. goto probe_exit;
  783. }
  784. if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) {
  785. dev_err(&pdev->dev, "HECC region already claimed\n");
  786. err = -EBUSY;
  787. goto probe_exit;
  788. }
  789. addr = ioremap(mem->start, resource_size(mem));
  790. if (!addr) {
  791. dev_err(&pdev->dev, "ioremap failed\n");
  792. err = -ENOMEM;
  793. goto probe_exit_free_region;
  794. }
  795. ndev = alloc_candev(sizeof(struct ti_hecc_priv), HECC_MAX_TX_MBOX);
  796. if (!ndev) {
  797. dev_err(&pdev->dev, "alloc_candev failed\n");
  798. err = -ENOMEM;
  799. goto probe_exit_iounmap;
  800. }
  801. priv = netdev_priv(ndev);
  802. priv->ndev = ndev;
  803. priv->base = addr;
  804. priv->scc_ram_offset = pdata->scc_ram_offset;
  805. priv->hecc_ram_offset = pdata->hecc_ram_offset;
  806. priv->mbx_offset = pdata->mbx_offset;
  807. priv->int_line = pdata->int_line;
  808. priv->transceiver_switch = pdata->transceiver_switch;
  809. priv->can.bittiming_const = &ti_hecc_bittiming_const;
  810. priv->can.do_set_mode = ti_hecc_do_set_mode;
  811. priv->can.do_get_state = ti_hecc_get_state;
  812. priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
  813. spin_lock_init(&priv->mbx_lock);
  814. ndev->irq = irq->start;
  815. ndev->flags |= IFF_ECHO;
  816. platform_set_drvdata(pdev, ndev);
  817. SET_NETDEV_DEV(ndev, &pdev->dev);
  818. ndev->netdev_ops = &ti_hecc_netdev_ops;
  819. priv->clk = clk_get(&pdev->dev, "hecc_ck");
  820. if (IS_ERR(priv->clk)) {
  821. dev_err(&pdev->dev, "No clock available\n");
  822. err = PTR_ERR(priv->clk);
  823. priv->clk = NULL;
  824. goto probe_exit_candev;
  825. }
  826. priv->can.clock.freq = clk_get_rate(priv->clk);
  827. netif_napi_add(ndev, &priv->napi, ti_hecc_rx_poll,
  828. HECC_DEF_NAPI_WEIGHT);
  829. clk_enable(priv->clk);
  830. err = register_candev(ndev);
  831. if (err) {
  832. dev_err(&pdev->dev, "register_candev() failed\n");
  833. goto probe_exit_clk;
  834. }
  835. dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%u)\n",
  836. priv->base, (u32) ndev->irq);
  837. return 0;
  838. probe_exit_clk:
  839. clk_put(priv->clk);
  840. probe_exit_candev:
  841. free_candev(ndev);
  842. probe_exit_iounmap:
  843. iounmap(addr);
  844. probe_exit_free_region:
  845. release_mem_region(mem->start, resource_size(mem));
  846. probe_exit:
  847. return err;
  848. }
  849. static int __devexit ti_hecc_remove(struct platform_device *pdev)
  850. {
  851. struct resource *res;
  852. struct net_device *ndev = platform_get_drvdata(pdev);
  853. struct ti_hecc_priv *priv = netdev_priv(ndev);
  854. clk_disable(priv->clk);
  855. clk_put(priv->clk);
  856. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  857. iounmap(priv->base);
  858. release_mem_region(res->start, resource_size(res));
  859. unregister_candev(ndev);
  860. free_candev(ndev);
  861. platform_set_drvdata(pdev, NULL);
  862. return 0;
  863. }
  864. #ifdef CONFIG_PM
  865. static int ti_hecc_suspend(struct platform_device *pdev, pm_message_t state)
  866. {
  867. struct net_device *dev = platform_get_drvdata(pdev);
  868. struct ti_hecc_priv *priv = netdev_priv(dev);
  869. if (netif_running(dev)) {
  870. netif_stop_queue(dev);
  871. netif_device_detach(dev);
  872. }
  873. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  874. priv->can.state = CAN_STATE_SLEEPING;
  875. clk_disable(priv->clk);
  876. return 0;
  877. }
  878. static int ti_hecc_resume(struct platform_device *pdev)
  879. {
  880. struct net_device *dev = platform_get_drvdata(pdev);
  881. struct ti_hecc_priv *priv = netdev_priv(dev);
  882. clk_enable(priv->clk);
  883. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  884. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  885. if (netif_running(dev)) {
  886. netif_device_attach(dev);
  887. netif_start_queue(dev);
  888. }
  889. return 0;
  890. }
  891. #else
  892. #define ti_hecc_suspend NULL
  893. #define ti_hecc_resume NULL
  894. #endif
  895. /* TI HECC netdevice driver: platform driver structure */
  896. static struct platform_driver ti_hecc_driver = {
  897. .driver = {
  898. .name = DRV_NAME,
  899. .owner = THIS_MODULE,
  900. },
  901. .probe = ti_hecc_probe,
  902. .remove = __devexit_p(ti_hecc_remove),
  903. .suspend = ti_hecc_suspend,
  904. .resume = ti_hecc_resume,
  905. };
  906. static int __init ti_hecc_init_driver(void)
  907. {
  908. printk(KERN_INFO DRV_DESC "\n");
  909. return platform_driver_register(&ti_hecc_driver);
  910. }
  911. static void __exit ti_hecc_exit_driver(void)
  912. {
  913. printk(KERN_INFO DRV_DESC " unloaded\n");
  914. platform_driver_unregister(&ti_hecc_driver);
  915. }
  916. module_exit(ti_hecc_exit_driver);
  917. module_init(ti_hecc_init_driver);
  918. MODULE_AUTHOR("Anant Gole <anantgole@ti.com>");
  919. MODULE_LICENSE("GPL v2");
  920. MODULE_DESCRIPTION(DRV_DESC);