Must i use module_spi_driver() in my linux kernel spi slave driver?
<p>I am trying to write a test driver to ADXL345 accelerometer for linux kernel. I split the devolopment process into 2 phases. First phase is read values by pulling mechanism. The second phase is cache the data when an interrupt occurs in the two interrupt leg of the accelerometer.</p>

<p>There is a nice documentation in here -> <a href="http://lxr.free-electrons.com/source/Documentation/spi/spi-summary?a=arm" rel="nofollow noreferrer">Linux official kernel documentation</a></p>

<p>And i investigated and based my code on -> <a href="https://github.com/rslemos/itrigue/blob/master/alsadriver/itrigue.c" rel="nofollow noreferrer">https://github.com/rslemos/itrigue/blob/master/alsadriver/itrigue.c</a></p>

<p>In the example i followed there is no <strong>spi_driver</strong> struct declared and used.</p>

<pre><code>adxlSpiDevice = spi_new_device(master, &amp;adxlSpiDeviceInfo);
</code></pre>

<p>But in official driver's source code spi_driver declared.</p>

<pre><code>module_spi_driver(adxl34x_driver);
</code></pre>

<p>So i confused about which approach must i choose or must i use both? </p>

<p>Here is my full code :</p>

<pre><code>/**
 * @file    idealSpiDriver.c
 * @author  Mehmet Ozgur Bayhan
 * @date    10.11.2016
 * @version 0.1
 * @brief   An introductory SPI driver.
 */

#include &lt;linux/kernel.h&gt;
#include &lt;linux/init.h&gt;
#include &lt;linux/module.h&gt;
#include &lt;linux/moduleparam.h&gt;
#include &lt;linux/gpio.h&gt;
#include &lt;linux/spi/spi.h&gt;


/* MP - Can be initialize as a parameter of a module */
// TODO : Set real values for these
static uint onoff_gpio = 139;
static uint adxl_spi_bus = 4;
static uint adxl_spi_cs = 0;
static uint speed_hz = 1500000;
static uint bits_per_word = 16;
/* -MP */

static struct spi_device *adxlSpiDevice;

static void adxl_spi_write(uint16_t write_data)
{
    spi_write(adxlSpiDevice, &amp;write_data, sizeof write_data);
}
static int adxl_spi_read(void *buf, size_t len)
{
    return spi_read(adxlSpiDevice, *buf,  len);
}


static int adxl_spi_init(void)
{
    struct spi_master *spiMaster;
    int retval;

    struct spi_board_info adxlSpiDeviceInfo;

    adxlSpiDeviceInfo.modalias = "idealSpiDriver";
    adxlSpiDeviceInfo.max_speed_hz = speed_hz;
    adxlSpiDeviceInfo.bus_num = adxl_spi_bus;
    adxlSpiDeviceInfo.chip_select = adxl_spi_cs;
    adxlSpiDeviceInfo.mode = 0;

    master = spi_busnum_to_master(adxlSpiDeviceInfo.bus_num);
    if ( !master )
    {
        return -ENODEV;
    }
    adxlSpiDevice = spi_new_device(master, &amp;adxlSpiDeviceInfo);
    if ( !adxlSpiDevice )
    {
        return -ENODEV;
    }
    adxlSpiDevice-&gt;bits_per_word = bits_per_word;
    retval = spi_setup(adxlSpiDevice);
    if ( retval )
    {
        spi_unregister_device(adxlSpiDevice);
    }
    else
    {
        printk(KERN_WARNING "MOB : Cant initialize spi device\n");
    }


    return retval;
}

// TODO: add __init before production
static int  adxl_driver_init(void)
{
    int retval;

    retval = adxl_spi_init();
    if (retval &gt; 0)
    {
        printk(KERN_INFO "MOB : IdealSpiDriver loaded\n");
    }
    return retval;
}

// TODO: add __exit before production
static void   adxl_driver_exit(void)
{
    spi_unregister_device(adxlSpiDevice);
    printk(KERN_INFO "MOB : IdealSpiDriver unloaded\n");
}


module_init(adxl_driver_init);
module_exit(adxl_driver_exit);


//static struct spi_driver adxl34x_driver = {
//  .driver = {
//      .name = "adxl34x",
//      .pm = &amp;adxl34x_spi_pm,
//  },
//  .probe   = adxl34x_spi_probe,
//  .remove  = adxl34x_spi_remove,
//};

//module_spi_driver(adxl34x_driver);

MODULE_AUTHOR("Mehmet Ozgur Bayhan");
MODULE_DESCRIPTION("Test Driver For ADXL345 Accelerometer");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");
</code></pre>

<p>I am planning to add a character device and pull data from userspace by that way. So must i register <strong>adxl34x_driver</strong> struct? If yes why?</p>