ti_hecc.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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. netdev_warn(priv->ndev, "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. netdev_info(priv->ndev, "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. netdev_dbg(ndev, "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. static int ti_hecc_get_berr_counter(const struct net_device *ndev,
  398. struct can_berr_counter *bec)
  399. {
  400. struct ti_hecc_priv *priv = netdev_priv(ndev);
  401. bec->txerr = hecc_read(priv, HECC_CANTEC);
  402. bec->rxerr = hecc_read(priv, HECC_CANREC);
  403. return 0;
  404. }
  405. /*
  406. * ti_hecc_xmit: HECC Transmit
  407. *
  408. * The transmit mailboxes start from 0 to HECC_MAX_TX_MBOX. In HECC the
  409. * priority of the mailbox for tranmission is dependent upon priority setting
  410. * field in mailbox registers. The mailbox with highest value in priority field
  411. * is transmitted first. Only when two mailboxes have the same value in
  412. * priority field the highest numbered mailbox is transmitted first.
  413. *
  414. * To utilize the HECC priority feature as described above we start with the
  415. * highest numbered mailbox with highest priority level and move on to the next
  416. * mailbox with the same priority level and so on. Once we loop through all the
  417. * transmit mailboxes we choose the next priority level (lower) and so on
  418. * until we reach the lowest priority level on the lowest numbered mailbox
  419. * when we stop transmission until all mailboxes are transmitted and then
  420. * restart at highest numbered mailbox with highest priority.
  421. *
  422. * Two counters (head and tail) are used to track the next mailbox to transmit
  423. * and to track the echo buffer for already transmitted mailbox. The queue
  424. * is stopped when all the mailboxes are busy or when there is a priority
  425. * value roll-over happens.
  426. */
  427. static netdev_tx_t ti_hecc_xmit(struct sk_buff *skb, struct net_device *ndev)
  428. {
  429. struct ti_hecc_priv *priv = netdev_priv(ndev);
  430. struct can_frame *cf = (struct can_frame *)skb->data;
  431. u32 mbxno, mbx_mask, data;
  432. unsigned long flags;
  433. if (can_dropped_invalid_skb(ndev, skb))
  434. return NETDEV_TX_OK;
  435. mbxno = get_tx_head_mb(priv);
  436. mbx_mask = BIT(mbxno);
  437. spin_lock_irqsave(&priv->mbx_lock, flags);
  438. if (unlikely(hecc_read(priv, HECC_CANME) & mbx_mask)) {
  439. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  440. netif_stop_queue(ndev);
  441. netdev_err(priv->ndev,
  442. "BUG: TX mbx not ready tx_head=%08X, tx_tail=%08X\n",
  443. priv->tx_head, priv->tx_tail);
  444. return NETDEV_TX_BUSY;
  445. }
  446. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  447. /* Prepare mailbox for transmission */
  448. data = cf->can_dlc | (get_tx_head_prio(priv) << 8);
  449. if (cf->can_id & CAN_RTR_FLAG) /* Remote transmission request */
  450. data |= HECC_CANMCF_RTR;
  451. hecc_write_mbx(priv, mbxno, HECC_CANMCF, data);
  452. if (cf->can_id & CAN_EFF_FLAG) /* Extended frame format */
  453. data = (cf->can_id & CAN_EFF_MASK) | HECC_CANMID_IDE;
  454. else /* Standard frame format */
  455. data = (cf->can_id & CAN_SFF_MASK) << 18;
  456. hecc_write_mbx(priv, mbxno, HECC_CANMID, data);
  457. hecc_write_mbx(priv, mbxno, HECC_CANMDL,
  458. be32_to_cpu(*(u32 *)(cf->data)));
  459. if (cf->can_dlc > 4)
  460. hecc_write_mbx(priv, mbxno, HECC_CANMDH,
  461. be32_to_cpu(*(u32 *)(cf->data + 4)));
  462. else
  463. *(u32 *)(cf->data + 4) = 0;
  464. can_put_echo_skb(skb, ndev, mbxno);
  465. spin_lock_irqsave(&priv->mbx_lock, flags);
  466. --priv->tx_head;
  467. if ((hecc_read(priv, HECC_CANME) & BIT(get_tx_head_mb(priv))) ||
  468. (priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK) {
  469. netif_stop_queue(ndev);
  470. }
  471. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  472. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  473. hecc_clear_bit(priv, HECC_CANMD, mbx_mask);
  474. hecc_set_bit(priv, HECC_CANMIM, mbx_mask);
  475. hecc_write(priv, HECC_CANTRS, mbx_mask);
  476. return NETDEV_TX_OK;
  477. }
  478. static int ti_hecc_rx_pkt(struct ti_hecc_priv *priv, int mbxno)
  479. {
  480. struct net_device_stats *stats = &priv->ndev->stats;
  481. struct can_frame *cf;
  482. struct sk_buff *skb;
  483. u32 data, mbx_mask;
  484. unsigned long flags;
  485. skb = alloc_can_skb(priv->ndev, &cf);
  486. if (!skb) {
  487. if (printk_ratelimit())
  488. netdev_err(priv->ndev,
  489. "ti_hecc_rx_pkt: alloc_can_skb() failed\n");
  490. return -ENOMEM;
  491. }
  492. mbx_mask = BIT(mbxno);
  493. data = hecc_read_mbx(priv, mbxno, HECC_CANMID);
  494. if (data & HECC_CANMID_IDE)
  495. cf->can_id = (data & CAN_EFF_MASK) | CAN_EFF_FLAG;
  496. else
  497. cf->can_id = (data >> 18) & CAN_SFF_MASK;
  498. data = hecc_read_mbx(priv, mbxno, HECC_CANMCF);
  499. if (data & HECC_CANMCF_RTR)
  500. cf->can_id |= CAN_RTR_FLAG;
  501. cf->can_dlc = get_can_dlc(data & 0xF);
  502. data = hecc_read_mbx(priv, mbxno, HECC_CANMDL);
  503. *(u32 *)(cf->data) = cpu_to_be32(data);
  504. if (cf->can_dlc > 4) {
  505. data = hecc_read_mbx(priv, mbxno, HECC_CANMDH);
  506. *(u32 *)(cf->data + 4) = cpu_to_be32(data);
  507. } else {
  508. *(u32 *)(cf->data + 4) = 0;
  509. }
  510. spin_lock_irqsave(&priv->mbx_lock, flags);
  511. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  512. hecc_write(priv, HECC_CANRMP, mbx_mask);
  513. /* enable mailbox only if it is part of rx buffer mailboxes */
  514. if (priv->rx_next < HECC_RX_BUFFER_MBOX)
  515. hecc_set_bit(priv, HECC_CANME, mbx_mask);
  516. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  517. stats->rx_bytes += cf->can_dlc;
  518. netif_receive_skb(skb);
  519. stats->rx_packets++;
  520. return 0;
  521. }
  522. /*
  523. * ti_hecc_rx_poll - HECC receive pkts
  524. *
  525. * The receive mailboxes start from highest numbered mailbox till last xmit
  526. * mailbox. On CAN frame reception the hardware places the data into highest
  527. * numbered mailbox that matches the CAN ID filter. Since all receive mailboxes
  528. * have same filtering (ALL CAN frames) packets will arrive in the highest
  529. * available RX mailbox and we need to ensure in-order packet reception.
  530. *
  531. * To ensure the packets are received in the right order we logically divide
  532. * the RX mailboxes into main and buffer mailboxes. Packets are received as per
  533. * mailbox priotity (higher to lower) in the main bank and once it is full we
  534. * disable further reception into main mailboxes. While the main mailboxes are
  535. * processed in NAPI, further packets are received in buffer mailboxes.
  536. *
  537. * We maintain a RX next mailbox counter to process packets and once all main
  538. * mailboxe packets are passed to the upper stack we enable all of them but
  539. * continue to process packets received in buffer mailboxes. With each packet
  540. * received from buffer mailbox we enable it immediately so as to handle the
  541. * overflow from higher mailboxes.
  542. */
  543. static int ti_hecc_rx_poll(struct napi_struct *napi, int quota)
  544. {
  545. struct net_device *ndev = napi->dev;
  546. struct ti_hecc_priv *priv = netdev_priv(ndev);
  547. u32 num_pkts = 0;
  548. u32 mbx_mask;
  549. unsigned long pending_pkts, flags;
  550. if (!netif_running(ndev))
  551. return 0;
  552. while ((pending_pkts = hecc_read(priv, HECC_CANRMP)) &&
  553. num_pkts < quota) {
  554. mbx_mask = BIT(priv->rx_next); /* next rx mailbox to process */
  555. if (mbx_mask & pending_pkts) {
  556. if (ti_hecc_rx_pkt(priv, priv->rx_next) < 0)
  557. return num_pkts;
  558. ++num_pkts;
  559. } else if (priv->rx_next > HECC_RX_BUFFER_MBOX) {
  560. break; /* pkt not received yet */
  561. }
  562. --priv->rx_next;
  563. if (priv->rx_next == HECC_RX_BUFFER_MBOX) {
  564. /* enable high bank mailboxes */
  565. spin_lock_irqsave(&priv->mbx_lock, flags);
  566. mbx_mask = hecc_read(priv, HECC_CANME);
  567. mbx_mask |= HECC_RX_HIGH_MBOX_MASK;
  568. hecc_write(priv, HECC_CANME, mbx_mask);
  569. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  570. } else if (priv->rx_next == HECC_MAX_TX_MBOX - 1) {
  571. priv->rx_next = HECC_RX_FIRST_MBOX;
  572. break;
  573. }
  574. }
  575. /* Enable packet interrupt if all pkts are handled */
  576. if (hecc_read(priv, HECC_CANRMP) == 0) {
  577. napi_complete(napi);
  578. /* Re-enable RX mailbox interrupts */
  579. mbx_mask = hecc_read(priv, HECC_CANMIM);
  580. mbx_mask |= HECC_TX_MBOX_MASK;
  581. hecc_write(priv, HECC_CANMIM, mbx_mask);
  582. }
  583. return num_pkts;
  584. }
  585. static int ti_hecc_error(struct net_device *ndev, int int_status,
  586. int err_status)
  587. {
  588. struct ti_hecc_priv *priv = netdev_priv(ndev);
  589. struct net_device_stats *stats = &ndev->stats;
  590. struct can_frame *cf;
  591. struct sk_buff *skb;
  592. /* propagate the error condition to the can stack */
  593. skb = alloc_can_err_skb(ndev, &cf);
  594. if (!skb) {
  595. if (printk_ratelimit())
  596. netdev_err(priv->ndev,
  597. "ti_hecc_error: alloc_can_err_skb() failed\n");
  598. return -ENOMEM;
  599. }
  600. if (int_status & HECC_CANGIF_WLIF) { /* warning level int */
  601. if ((int_status & HECC_CANGIF_BOIF) == 0) {
  602. priv->can.state = CAN_STATE_ERROR_WARNING;
  603. ++priv->can.can_stats.error_warning;
  604. cf->can_id |= CAN_ERR_CRTL;
  605. if (hecc_read(priv, HECC_CANTEC) > 96)
  606. cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;
  607. if (hecc_read(priv, HECC_CANREC) > 96)
  608. cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
  609. }
  610. hecc_set_bit(priv, HECC_CANES, HECC_CANES_EW);
  611. netdev_dbg(priv->ndev, "Error Warning interrupt\n");
  612. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  613. }
  614. if (int_status & HECC_CANGIF_EPIF) { /* error passive int */
  615. if ((int_status & HECC_CANGIF_BOIF) == 0) {
  616. priv->can.state = CAN_STATE_ERROR_PASSIVE;
  617. ++priv->can.can_stats.error_passive;
  618. cf->can_id |= CAN_ERR_CRTL;
  619. if (hecc_read(priv, HECC_CANTEC) > 127)
  620. cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
  621. if (hecc_read(priv, HECC_CANREC) > 127)
  622. cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
  623. }
  624. hecc_set_bit(priv, HECC_CANES, HECC_CANES_EP);
  625. netdev_dbg(priv->ndev, "Error passive interrupt\n");
  626. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  627. }
  628. /*
  629. * Need to check busoff condition in error status register too to
  630. * ensure warning interrupts don't hog the system
  631. */
  632. if ((int_status & HECC_CANGIF_BOIF) || (err_status & HECC_CANES_BO)) {
  633. priv->can.state = CAN_STATE_BUS_OFF;
  634. cf->can_id |= CAN_ERR_BUSOFF;
  635. hecc_set_bit(priv, HECC_CANES, HECC_CANES_BO);
  636. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_CCR);
  637. /* Disable all interrupts in bus-off to avoid int hog */
  638. hecc_write(priv, HECC_CANGIM, 0);
  639. can_bus_off(ndev);
  640. }
  641. if (err_status & HECC_BUS_ERROR) {
  642. ++priv->can.can_stats.bus_error;
  643. cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
  644. cf->data[2] |= CAN_ERR_PROT_UNSPEC;
  645. if (err_status & HECC_CANES_FE) {
  646. hecc_set_bit(priv, HECC_CANES, HECC_CANES_FE);
  647. cf->data[2] |= CAN_ERR_PROT_FORM;
  648. }
  649. if (err_status & HECC_CANES_BE) {
  650. hecc_set_bit(priv, HECC_CANES, HECC_CANES_BE);
  651. cf->data[2] |= CAN_ERR_PROT_BIT;
  652. }
  653. if (err_status & HECC_CANES_SE) {
  654. hecc_set_bit(priv, HECC_CANES, HECC_CANES_SE);
  655. cf->data[2] |= CAN_ERR_PROT_STUFF;
  656. }
  657. if (err_status & HECC_CANES_CRCE) {
  658. hecc_set_bit(priv, HECC_CANES, HECC_CANES_CRCE);
  659. cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ |
  660. CAN_ERR_PROT_LOC_CRC_DEL;
  661. }
  662. if (err_status & HECC_CANES_ACKE) {
  663. hecc_set_bit(priv, HECC_CANES, HECC_CANES_ACKE);
  664. cf->data[3] |= CAN_ERR_PROT_LOC_ACK |
  665. CAN_ERR_PROT_LOC_ACK_DEL;
  666. }
  667. }
  668. netif_rx(skb);
  669. stats->rx_packets++;
  670. stats->rx_bytes += cf->can_dlc;
  671. return 0;
  672. }
  673. static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)
  674. {
  675. struct net_device *ndev = (struct net_device *)dev_id;
  676. struct ti_hecc_priv *priv = netdev_priv(ndev);
  677. struct net_device_stats *stats = &ndev->stats;
  678. u32 mbxno, mbx_mask, int_status, err_status;
  679. unsigned long ack, flags;
  680. int_status = hecc_read(priv,
  681. (priv->int_line) ? HECC_CANGIF1 : HECC_CANGIF0);
  682. if (!int_status)
  683. return IRQ_NONE;
  684. err_status = hecc_read(priv, HECC_CANES);
  685. if (err_status & (HECC_BUS_ERROR | HECC_CANES_BO |
  686. HECC_CANES_EP | HECC_CANES_EW))
  687. ti_hecc_error(ndev, int_status, err_status);
  688. if (int_status & HECC_CANGIF_GMIF) {
  689. while (priv->tx_tail - priv->tx_head > 0) {
  690. mbxno = get_tx_tail_mb(priv);
  691. mbx_mask = BIT(mbxno);
  692. if (!(mbx_mask & hecc_read(priv, HECC_CANTA)))
  693. break;
  694. hecc_clear_bit(priv, HECC_CANMIM, mbx_mask);
  695. hecc_write(priv, HECC_CANTA, mbx_mask);
  696. spin_lock_irqsave(&priv->mbx_lock, flags);
  697. hecc_clear_bit(priv, HECC_CANME, mbx_mask);
  698. spin_unlock_irqrestore(&priv->mbx_lock, flags);
  699. stats->tx_bytes += hecc_read_mbx(priv, mbxno,
  700. HECC_CANMCF) & 0xF;
  701. stats->tx_packets++;
  702. can_get_echo_skb(ndev, mbxno);
  703. --priv->tx_tail;
  704. }
  705. /* restart queue if wrap-up or if queue stalled on last pkt */
  706. if (((priv->tx_head == priv->tx_tail) &&
  707. ((priv->tx_head & HECC_TX_MASK) != HECC_TX_MASK)) ||
  708. (((priv->tx_tail & HECC_TX_MASK) == HECC_TX_MASK) &&
  709. ((priv->tx_head & HECC_TX_MASK) == HECC_TX_MASK)))
  710. netif_wake_queue(ndev);
  711. /* Disable RX mailbox interrupts and let NAPI reenable them */
  712. if (hecc_read(priv, HECC_CANRMP)) {
  713. ack = hecc_read(priv, HECC_CANMIM);
  714. ack &= BIT(HECC_MAX_TX_MBOX) - 1;
  715. hecc_write(priv, HECC_CANMIM, ack);
  716. napi_schedule(&priv->napi);
  717. }
  718. }
  719. /* clear all interrupt conditions - read back to avoid spurious ints */
  720. if (priv->int_line) {
  721. hecc_write(priv, HECC_CANGIF1, HECC_SET_REG);
  722. int_status = hecc_read(priv, HECC_CANGIF1);
  723. } else {
  724. hecc_write(priv, HECC_CANGIF0, HECC_SET_REG);
  725. int_status = hecc_read(priv, HECC_CANGIF0);
  726. }
  727. return IRQ_HANDLED;
  728. }
  729. static int ti_hecc_open(struct net_device *ndev)
  730. {
  731. struct ti_hecc_priv *priv = netdev_priv(ndev);
  732. int err;
  733. err = request_irq(ndev->irq, ti_hecc_interrupt, IRQF_SHARED,
  734. ndev->name, ndev);
  735. if (err) {
  736. netdev_err(ndev, "error requesting interrupt\n");
  737. return err;
  738. }
  739. ti_hecc_transceiver_switch(priv, 1);
  740. /* Open common can device */
  741. err = open_candev(ndev);
  742. if (err) {
  743. netdev_err(ndev, "open_candev() failed %d\n", err);
  744. ti_hecc_transceiver_switch(priv, 0);
  745. free_irq(ndev->irq, ndev);
  746. return err;
  747. }
  748. ti_hecc_start(ndev);
  749. napi_enable(&priv->napi);
  750. netif_start_queue(ndev);
  751. return 0;
  752. }
  753. static int ti_hecc_close(struct net_device *ndev)
  754. {
  755. struct ti_hecc_priv *priv = netdev_priv(ndev);
  756. netif_stop_queue(ndev);
  757. napi_disable(&priv->napi);
  758. ti_hecc_stop(ndev);
  759. free_irq(ndev->irq, ndev);
  760. close_candev(ndev);
  761. ti_hecc_transceiver_switch(priv, 0);
  762. return 0;
  763. }
  764. static const struct net_device_ops ti_hecc_netdev_ops = {
  765. .ndo_open = ti_hecc_open,
  766. .ndo_stop = ti_hecc_close,
  767. .ndo_start_xmit = ti_hecc_xmit,
  768. };
  769. static int ti_hecc_probe(struct platform_device *pdev)
  770. {
  771. struct net_device *ndev = (struct net_device *)0;
  772. struct ti_hecc_priv *priv;
  773. struct ti_hecc_platform_data *pdata;
  774. struct resource *mem, *irq;
  775. void __iomem *addr;
  776. int err = -ENODEV;
  777. pdata = pdev->dev.platform_data;
  778. if (!pdata) {
  779. dev_err(&pdev->dev, "No platform data\n");
  780. goto probe_exit;
  781. }
  782. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  783. if (!mem) {
  784. dev_err(&pdev->dev, "No mem resources\n");
  785. goto probe_exit;
  786. }
  787. irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  788. if (!irq) {
  789. dev_err(&pdev->dev, "No irq resource\n");
  790. goto probe_exit;
  791. }
  792. if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) {
  793. dev_err(&pdev->dev, "HECC region already claimed\n");
  794. err = -EBUSY;
  795. goto probe_exit;
  796. }
  797. addr = ioremap(mem->start, resource_size(mem));
  798. if (!addr) {
  799. dev_err(&pdev->dev, "ioremap failed\n");
  800. err = -ENOMEM;
  801. goto probe_exit_free_region;
  802. }
  803. ndev = alloc_candev(sizeof(struct ti_hecc_priv), HECC_MAX_TX_MBOX);
  804. if (!ndev) {
  805. dev_err(&pdev->dev, "alloc_candev failed\n");
  806. err = -ENOMEM;
  807. goto probe_exit_iounmap;
  808. }
  809. priv = netdev_priv(ndev);
  810. priv->ndev = ndev;
  811. priv->base = addr;
  812. priv->scc_ram_offset = pdata->scc_ram_offset;
  813. priv->hecc_ram_offset = pdata->hecc_ram_offset;
  814. priv->mbx_offset = pdata->mbx_offset;
  815. priv->int_line = pdata->int_line;
  816. priv->transceiver_switch = pdata->transceiver_switch;
  817. priv->can.bittiming_const = &ti_hecc_bittiming_const;
  818. priv->can.do_set_mode = ti_hecc_do_set_mode;
  819. priv->can.do_get_state = ti_hecc_get_state;
  820. priv->can.do_get_berr_counter = ti_hecc_get_berr_counter;
  821. priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
  822. spin_lock_init(&priv->mbx_lock);
  823. ndev->irq = irq->start;
  824. ndev->flags |= IFF_ECHO;
  825. platform_set_drvdata(pdev, ndev);
  826. SET_NETDEV_DEV(ndev, &pdev->dev);
  827. ndev->netdev_ops = &ti_hecc_netdev_ops;
  828. priv->clk = clk_get(&pdev->dev, "hecc_ck");
  829. if (IS_ERR(priv->clk)) {
  830. dev_err(&pdev->dev, "No clock available\n");
  831. err = PTR_ERR(priv->clk);
  832. priv->clk = NULL;
  833. goto probe_exit_candev;
  834. }
  835. priv->can.clock.freq = clk_get_rate(priv->clk);
  836. netif_napi_add(ndev, &priv->napi, ti_hecc_rx_poll,
  837. HECC_DEF_NAPI_WEIGHT);
  838. clk_enable(priv->clk);
  839. err = register_candev(ndev);
  840. if (err) {
  841. dev_err(&pdev->dev, "register_candev() failed\n");
  842. goto probe_exit_clk;
  843. }
  844. dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%u)\n",
  845. priv->base, (u32) ndev->irq);
  846. return 0;
  847. probe_exit_clk:
  848. clk_put(priv->clk);
  849. probe_exit_candev:
  850. free_candev(ndev);
  851. probe_exit_iounmap:
  852. iounmap(addr);
  853. probe_exit_free_region:
  854. release_mem_region(mem->start, resource_size(mem));
  855. probe_exit:
  856. return err;
  857. }
  858. static int __devexit ti_hecc_remove(struct platform_device *pdev)
  859. {
  860. struct resource *res;
  861. struct net_device *ndev = platform_get_drvdata(pdev);
  862. struct ti_hecc_priv *priv = netdev_priv(ndev);
  863. unregister_candev(ndev);
  864. clk_disable(priv->clk);
  865. clk_put(priv->clk);
  866. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  867. iounmap(priv->base);
  868. release_mem_region(res->start, resource_size(res));
  869. free_candev(ndev);
  870. platform_set_drvdata(pdev, NULL);
  871. return 0;
  872. }
  873. #ifdef CONFIG_PM
  874. static int ti_hecc_suspend(struct platform_device *pdev, pm_message_t state)
  875. {
  876. struct net_device *dev = platform_get_drvdata(pdev);
  877. struct ti_hecc_priv *priv = netdev_priv(dev);
  878. if (netif_running(dev)) {
  879. netif_stop_queue(dev);
  880. netif_device_detach(dev);
  881. }
  882. hecc_set_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  883. priv->can.state = CAN_STATE_SLEEPING;
  884. clk_disable(priv->clk);
  885. return 0;
  886. }
  887. static int ti_hecc_resume(struct platform_device *pdev)
  888. {
  889. struct net_device *dev = platform_get_drvdata(pdev);
  890. struct ti_hecc_priv *priv = netdev_priv(dev);
  891. clk_enable(priv->clk);
  892. hecc_clear_bit(priv, HECC_CANMC, HECC_CANMC_PDR);
  893. priv->can.state = CAN_STATE_ERROR_ACTIVE;
  894. if (netif_running(dev)) {
  895. netif_device_attach(dev);
  896. netif_start_queue(dev);
  897. }
  898. return 0;
  899. }
  900. #else
  901. #define ti_hecc_suspend NULL
  902. #define ti_hecc_resume NULL
  903. #endif
  904. /* TI HECC netdevice driver: platform driver structure */
  905. static struct platform_driver ti_hecc_driver = {
  906. .driver = {
  907. .name = DRV_NAME,
  908. .owner = THIS_MODULE,
  909. },
  910. .probe = ti_hecc_probe,
  911. .remove = __devexit_p(ti_hecc_remove),
  912. .suspend = ti_hecc_suspend,
  913. .resume = ti_hecc_resume,
  914. };
  915. module_platform_driver(ti_hecc_driver);
  916. MODULE_AUTHOR("Anant Gole <anantgole@ti.com>");
  917. MODULE_LICENSE("GPL v2");
  918. MODULE_DESCRIPTION(DRV_DESC);