static int
ads_spi_probe(struct spi_device *spi)
{
ads_data_t *ads; //--> driver data struct
int err = 0;
/* Is there a matching device in the device tree? */
if (!of_match_device(ads1274_dt_ids, &spi->dev)) {
err = -ENODEV;
goto error;
}
debug("Probed compat. devices: %s", //--> .compatible = "ti,ads1274",
ads1274_dt_ids[0].compatible);
/* Then allocate the driver data */
ads = (ads_data_t *)kzalloc(sizeof(ads_data_t), GFP_KERNEL);
if (IS_ERR(ads)) {
err = PTR_ERR(ads);
debug("Could not allocate driver data: ERR %d", err);
goto error;
}
debug("Initialized SPI data structure at %p", ads);
init_waitqueue_head(&ads->wait_read);
spin_lock_init(&ads->spi_lock);
INIT_LIST_HEAD(&device_list);
mutex_lock(&device_list_lock);
/* Request and configure GPIO trigger */
err = ads_gpio_init(&ads->gpio, p9, true, true);
if (err < 0) {
pr_err("%s: Could not initialze GPIO %d", MODNAME, p9);
goto free_driver_data;
}
debug("GPIO pin %d mapped to irq %d",
ads->gpio.pin, ads->gpio.irq_number);
/* Request 1 minor device number from the kernel */
if (alloc_chrdev_region(&ads->devt, 0, 1, MODNAME) < 0) {
err = -EIO;
goto free_workqueue;
}
debug("Requested major/minor %d : %d", MAJOR(ads->devt), MINOR(ads->devt));
/* SPI setup */
ads->spi = spi;
spi_set_drvdata(spi, ads);
spi_setup(ads->spi); //--> should init dma channels
debug("spi: %p", ads->spi);
debug("spi m: %p", ads->spi->master);
debug("spi m rx: %p", ads->spi->master->dma_rx); //--> NULL
debug("spi m tx: %p", ads->spi->master->dma_tx); //--> NULL
/* Create character device */
ads->cdev = cdev_alloc();
if (ads->cdev == NULL)
goto free_chrdev_region;
debug("Cdev initialized");
ads->cdev->owner = THIS_MODULE;
ads->cdev->ops = &fops;
if (cdev_add(ads->cdev, ads->devt, 1))
goto free_cdev;
device_create(ads_class, &ads->spi->dev, ads->devt, ads->spi,
"ads1274-spi%d.%d", ads->spi->master->bus_num, ads->spi->chip_select);
list_add_tail(&(ads->device_entry), &device_list);
mutex_unlock(&device_list_lock);
pr_info("%s: Added SPI device %s-spi%d.%d", MODNAME, spi->modalias,
spi->master->bus_num, spi->chip_select);
/* Should be 0 */
return err;
free_cdev:
kobject_put(&(ads->cdev->kobj));
free_chrdev_region:
unregister_chrdev_region(ads->devt, 1);
free_workqueue:
// ads_workqueue_free(&ads);
//free_gpio:
ads_gpio_free(&(ads->gpio));
free_driver_data:
kfree(ads);
debug("There was an error while probing devices");
error:
return err;
}