Merge tag 'dm-4.1-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / dgnc / dgnc_driver.c
index f177d3a258c2cf8bce2c2f18182b19167e6155f7..805dc617e3a787b86a38142d2760fa8cdc2e4ed5 100644 (file)
  * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- *     NOTE TO LINUX KERNEL HACKERS:  DO NOT REFORMAT THIS CODE!
- *
- *     This is shared code between Digi's CVS archive and the
- *     Linux Kernel sources.
- *     Changing the source just for reformatting needlessly breaks
- *     our CVS diff history.
- *
- *     Send any bug fixes/changes to:  Eng.Linux at digi dot com.
- *     Thank you.
- *
  */
 
 
@@ -37,7 +21,6 @@
 #include <linux/sched.h>
 #include "dgnc_driver.h"
 #include "dgnc_pci.h"
-#include "dpacompat.h"
 #include "dgnc_mgmt.h"
 #include "dgnc_tty.h"
 #include "dgnc_cls.h"
@@ -60,7 +43,8 @@ static void           dgnc_init_globals(void);
 static int             dgnc_found_board(struct pci_dev *pdev, int id);
 static void            dgnc_cleanup_board(struct dgnc_board *brd);
 static void            dgnc_poll_handler(ulong dummy);
-static int             dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
+static int             dgnc_init_one(struct pci_dev *pdev,
+                                     const struct pci_device_id *ent);
 static void            dgnc_do_remap(struct dgnc_board *brd);
 
 /*
@@ -92,8 +76,8 @@ static struct class *dgnc_class;
  * Poller stuff
  */
 static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
-static ulong           dgnc_poll_time;                         /* Time of next poll */
-static uint            dgnc_poll_stop;                         /* Used to tell poller to stop */
+static ulong           dgnc_poll_time; /* Time of next poll */
+static uint            dgnc_poll_stop; /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
 
 
@@ -139,14 +123,6 @@ static struct pci_driver dgnc_driver = {
        .id_table       = dgnc_pci_tbl,
 };
 
-
-char *dgnc_state_text[] = {
-       "Board Failed",
-       "Board Found",
-       "Board READY",
-};
-
-
 /************************************************************************
  *
  * Driver load/unload functions
@@ -214,7 +190,7 @@ static int __init dgnc_init_module(void)
         * If something went wrong in the scan, bail out of driver.
         */
        if (rc < 0) {
-               /* Only unregister the pci driver if it was actually registered. */
+               /* Only unregister if it was actually registered. */
                if (dgnc_NumBoards)
                        pci_unregister_driver(&dgnc_driver);
                else
@@ -251,9 +227,9 @@ static int dgnc_start(void)
         * Register management/dpa devices
         */
        rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
-       if (rc <= 0) {
+       if (rc < 0) {
                pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
-               return -ENXIO;
+               return rc;
        }
        dgnc_Major = rc;
 
@@ -285,9 +261,7 @@ static int dgnc_start(void)
 
        /* Start the poller */
        spin_lock_irqsave(&dgnc_poll_lock, flags);
-       init_timer(&dgnc_poll_timer);
-       dgnc_poll_timer.function = dgnc_poll_handler;
-       dgnc_poll_timer.data = 0;
+       setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
        dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
        dgnc_poll_timer.expires = dgnc_poll_time;
        spin_unlock_irqrestore(&dgnc_poll_lock, flags);
@@ -364,7 +338,7 @@ static void dgnc_cleanup_board(struct dgnc_board *brd)
 
                spin_lock_irqsave(&dgnc_global_lock, flags);
                brd->msgbuf = NULL;
-               printk("%s", brd->msgbuf_head);
+               dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
                kfree(brd->msgbuf_head);
                brd->msgbuf_head = NULL;
                spin_unlock_irqrestore(&dgnc_global_lock, flags);
@@ -410,7 +384,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
                return -ENOMEM;
 
        /* make a temporary message buffer for the boot messages */
-       brd->msgbuf_head = kzalloc(sizeof(u8) * 8192, GFP_KERNEL);
+       brd->msgbuf_head = kcalloc(8192, sizeof(u8), GFP_KERNEL);
        brd->msgbuf = brd->msgbuf_head;
 
        if (!brd->msgbuf) {
@@ -553,7 +527,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
                if (brd->re_map_membase) {
 
-                       /* After remap is complete, we need to read and store the dvid */
+                       /* Read and store the dvid after remapping */
                        brd->dvid = readb(brd->re_map_membase + 0x8D);
 
                        /* Get and store the board VPD, if it exists */
@@ -574,29 +548,19 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
        rc = dgnc_tty_register(brd);
        if (rc < 0) {
-               dgnc_tty_uninit(brd);
                pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
-               brd->state = BOARD_FAILED;
-               brd->dpastatus = BD_NOFEP;
                goto failed;
        }
 
        rc = dgnc_finalize_board_init(brd);
        if (rc < 0) {
                pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
-               brd->state = BOARD_FAILED;
-               brd->dpastatus = BD_NOFEP;
-
                goto failed;
        }
 
        rc = dgnc_tty_init(brd);
        if (rc < 0) {
-               dgnc_tty_uninit(brd);
                pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
-               brd->state = BOARD_FAILED;
-               brd->dpastatus = BD_NOFEP;
-
                goto failed;
        }
 
@@ -606,11 +570,13 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
        dgnc_create_ports_sysfiles(brd);
 
        /* init our poll helper tasklet */
-       tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
+       tasklet_init(&brd->helper_tasklet,
+                    brd->bd_ops->tasklet,
+                    (unsigned long) brd);
 
        spin_lock_irqsave(&dgnc_global_lock, flags);
        brd->msgbuf = NULL;
-       printk("%s", brd->msgbuf_head);
+       dev_dbg(&brd->pdev->dev, "%s\n", brd->msgbuf_head);
        kfree(brd->msgbuf_head);
        brd->msgbuf_head = NULL;
        spin_unlock_irqrestore(&dgnc_global_lock, flags);
@@ -628,6 +594,9 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
        return 0;
 
 failed:
+       dgnc_tty_uninit(brd);
+       brd->state = BOARD_FAILED;
+       brd->dpastatus = BD_NOFEP;
 
        return -ENXIO;
 
@@ -708,7 +677,7 @@ static void dgnc_poll_handler(ulong dummy)
 
                spin_lock_irqsave(&brd->bd_lock, flags);
 
-               /* If board is in a failed state, don't bother scheduling a tasklet */
+               /* If board is in a failed state don't schedule a tasklet */
                if (brd->state == BOARD_FAILED) {
                        spin_unlock_irqrestore(&brd->bd_lock, flags);
                        continue;
@@ -729,11 +698,9 @@ static void dgnc_poll_handler(ulong dummy)
        new_time = dgnc_poll_time - jiffies;
 
        if ((ulong) new_time >= 2 * dgnc_poll_tick)
-               dgnc_poll_time = jiffies +  dgnc_jiffies_from_ms(dgnc_poll_tick);
+               dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
 
-       init_timer(&dgnc_poll_timer);
-       dgnc_poll_timer.function = dgnc_poll_handler;
-       dgnc_poll_timer.data = 0;
+       setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
        dgnc_poll_timer.expires = dgnc_poll_time;
        spin_unlock_irqrestore(&dgnc_poll_lock, flags);