Rename ELM_ to ELM327_STATE_
[elmcan.git] / module / elmcan.c
index 7b22728a35a458dc460d6a8613134d2bd12b3106..ed652de890761db84a91306407c0d06093895a77 100644 (file)
 #include <linux/can/led.h>
 #include <linux/can/rx-offload.h>
 
-MODULE_ALIAS_LDISC(N_DEVELOPMENT);
-MODULE_DESCRIPTION("ELM327 based CAN interface");
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Max Staudt <max-linux@enpas.org>");
-
 /* Line discipline ID number.
  * N_DEVELOPMENT will likely be defined from Linux 5.18 onwards:
  * https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=c2faf737abfb10f88f2d2612d573e9edc3c42c37
@@ -94,11 +89,11 @@ struct elmcan {
        struct can_rx_offload offload;
 
        /* TTY and netdev devices that we're bridging */
-       struct tty_struct       *tty;
-       struct net_device       *dev;
+       struct tty_struct *tty;
+       struct net_device *dev;
 
        /* Per-channel lock */
-       spinlock_t              lock;
+       spinlock_t lock;
 
        /* Keep track of how many things are using this struct.
         * Once it reaches 0, we are in the process of cleaning up,
@@ -107,18 +102,18 @@ struct elmcan {
         * decrement to 0, and refcount_dec() spills a WARN_ONCE in
         * that case.
         */
-       atomic_t                refcount;
+       atomic_t refcount;
 
        /* Stop the channel on hardware failure.
         * Once this is true, nothing will be sent to the TTY.
         */
-       bool                    hw_failure;
+       bool hw_failure;
 
        /* TTY TX helpers */
-       struct work_struct      tx_work;        /* Flushes TTY TX buffer   */
-       unsigned char           *txbuf;
-       unsigned char           *txhead;        /* Pointer to next TX byte */
-       int                     txleft;         /* Bytes left to TX */
+       struct work_struct tx_work;     /* Flushes TTY TX buffer   */
+       unsigned char *txbuf;
+       unsigned char *txhead;          /* Pointer to next TX byte */
+       int txleft;                     /* Bytes left to TX */
 
        /* TTY RX helpers */
        unsigned char rxbuf[ELM327_SIZE_RXBUF];
@@ -126,10 +121,10 @@ struct elmcan {
 
        /* State machine */
        enum {
-               ELM_NOTINIT = 0,
-               ELM_GETDUMMYCHAR,
-               ELM_GETPROMPT,
-               ELM_RECEIVING,
+               ELM327_STATE_NOTINIT = 0,
+               ELM327_STATE_GETDUMMYCHAR,
+               ELM327_STATE_GETPROMPT,
+               ELM327_STATE_RECEIVING,
        } state;
 
        int drop_next_line;
@@ -198,10 +193,11 @@ static void elm327_send(struct elmcan *elm, const void *buf, size_t len)
  */
 static void elm327_kick_into_cmd_mode(struct elmcan *elm)
 {
-       if (elm->state != ELM_GETDUMMYCHAR && elm->state != ELM_GETPROMPT) {
+       if (elm->state != ELM327_STATE_GETDUMMYCHAR &&
+           elm->state != ELM327_STATE_GETPROMPT) {
                elm327_send(elm, ELM327_DUMMY_STRING, 1);
 
-               elm->state = ELM_GETDUMMYCHAR;
+               elm->state = ELM327_STATE_GETDUMMYCHAR;
        }
 }
 
@@ -272,7 +268,7 @@ static char *elm327_init_script[] = {
 
 static void elm327_init(struct elmcan *elm)
 {
-       elm->state = ELM_NOTINIT;
+       elm->state = ELM327_STATE_NOTINIT;
        elm->can_frame_to_send.can_id = 0x7df; /* ELM327 HW default */
        elm->rxfill = 0;
        elm->drop_next_line = 0;
@@ -568,7 +564,7 @@ static void elm327_parse_line(struct elmcan *elm, size_t len)
        }
 
        /* Regular parsing */
-       if (elm->state == ELM_RECEIVING
+       if (elm->state == ELM327_STATE_RECEIVING
            && elm327_parse_frame(elm, len)) {
                /* Parse an error line. */
                elm327_parse_error(elm, len);
@@ -587,7 +583,7 @@ static void elm327_handle_prompt(struct elmcan *elm)
        if (!elm->cmds_todo) {
                /* Enter CAN monitor mode */
                elm327_send(elm, "ATMA\r", 5);
-               elm->state = ELM_RECEIVING;
+               elm->state = ELM327_STATE_RECEIVING;
 
                return;
        }
@@ -649,7 +645,7 @@ static void elm327_handle_prompt(struct elmcan *elm)
                }
 
                elm->drop_next_line = 1;
-               elm->state = ELM_RECEIVING;
+               elm->state = ELM327_STATE_RECEIVING;
        }
 
        elm327_send(elm, local_txbuf, strlen(local_txbuf));
@@ -677,17 +673,17 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
        int i;
 
        switch (elm->state) {
-       case ELM_NOTINIT:
+       case ELM327_STATE_NOTINIT:
                elm->rxfill = 0;
                break;
 
-       case ELM_GETDUMMYCHAR:
+       case ELM327_STATE_GETDUMMYCHAR:
        {
                /* Wait for 'y' or '>' */
                for (i = 0; i < elm->rxfill; i++) {
                        if (elm->rxbuf[i] == ELM327_DUMMY_CHAR) {
                                elm327_send(elm, "\r", 1);
-                               elm->state = ELM_GETPROMPT;
+                               elm->state = ELM327_STATE_GETPROMPT;
                                i++;
                                break;
                        } else if (elm327_is_ready_char(elm->rxbuf[i])) {
@@ -702,7 +698,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
                break;
        }
 
-       case ELM_GETPROMPT:
+       case ELM327_STATE_GETPROMPT:
                /* Wait for '>' */
                if (elm327_is_ready_char(elm->rxbuf[elm->rxfill - 1]))
                        elm327_handle_prompt(elm);
@@ -710,7 +706,7 @@ static void elm327_parse_rxbuf(struct elmcan *elm)
                elm->rxfill = 0;
                break;
 
-       case ELM_RECEIVING:
+       case ELM327_STATE_RECEIVING:
                /* Find <CR> delimiting feedback lines. */
                for (len = 0;
                     (len < elm->rxfill) && (elm->rxbuf[len] != '\r');
@@ -1287,3 +1283,8 @@ static void __exit elmcan_exit(void)
 
 module_init(elmcan_init);
 module_exit(elmcan_exit);
+
+MODULE_ALIAS_LDISC(N_DEVELOPMENT);
+MODULE_DESCRIPTION("ELM327 based CAN interface");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Max Staudt <max-linux@enpas.org>");