static int p3_enable_clk_cs(struct p3_dev *p3_device) { int ret_val = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; //P3_DBG_MSG("%s CLK is %lu.\n", __func__, clock); spin_lock_irq(&p3_device->ese_spi_lock); spidev = spi_dev_get(p3_device->spi); spin_unlock_irq(&p3_device->ese_spi_lock); if (spidev == NULL) { P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -1; } sdd = spi_master_get_devdata(spidev->master); if (!sdd){ P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -EFAULT; } pm_runtime_get_sync(&sdd->pdev->dev); /* Enable clk */ /* set spi clock rate */ //clk_set_rate(sdd->src_clk, clock * 2); p3_device->enabled_clk = true; spi_dev_put(spidev); /* CS control*/ gpio_set_value(p3_device->cs_gpio, 0); usleep_range(50,70); return ret_val; }
/* Normal World */ static int p61_ioctl_config_spi_gpio( struct p61_dev *p61_device) { struct spi_device *spidev = NULL; int ret_val = 0; if (!p61_device->isGpio_cfgDone) { pr_info("%s SET_SPI_CONFIGURATION\n", __func__); spin_lock_irq(&p61_device->ese_spi_lock); spidev = spi_dev_get(p61_device->spi); spin_unlock_irq(&p61_device->ese_spi_lock); #if 0 ret_val = ese_spi_request_gpios(spidev); if (ret_val < 0) pr_err("%s: couldn't config spi gpio\n", __func__); #endif p61_device->isGpio_cfgDone = true; p61_device->null_buffer = kmalloc(DEFAULT_BUFFER_SIZE, GFP_KERNEL); if (p61_device->null_buffer == NULL) { ret_val = -ENOMEM; pr_err("%s null_buffer == NULL, -ENOMEM\n", __func__); //goto vfsspi_open_out; } p61_device->buffer = kmalloc(DEFAULT_BUFFER_SIZE, GFP_KERNEL); if (p61_device->buffer == NULL) { ret_val = -ENOMEM; kfree(p61_device->null_buffer); pr_err("%s buffer == NULL, -ENOMEM\n", __func__); //goto vfsspi_open_out; } spi_dev_put(spidev); usleep_range(950, 1000); } return ret_val; }
static int p3_set_clk(struct p3_dev *p3_device, unsigned long arg) { int ret_val = 0; unsigned long clock = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; if (arg >= 100000) clock = arg; else return -1; P3_DBG_MSG("%s CLK is %lu.\n", __func__, clock); spin_lock_irq(&p3_device->ese_spi_lock); spidev = spi_dev_get(p3_device->spi); spin_unlock_irq(&p3_device->ese_spi_lock); if (spidev == NULL) { P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -1; } //if (clock < 10000) // clock = P3_SPI_CLOCK; spidev->max_speed_hz = (u32)clock; sdd = spi_master_get_devdata(spidev->master); if (!sdd){ P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -EFAULT; } /*pm_runtime_get_sync(&sdd->pdev->dev);*/ /*Need to move to Enable*/ /*P3_DBG_MSG("%s pm_runtime_get_sync.\n", __func__);*/ /* set spi clock rate */ clk_set_rate(sdd->src_clk, clock * 2); spi_dev_put(spidev); return ret_val; }
static int add_gpio_pmodoled_device_to_bus(struct gpio_pmodoled_device *dev) { struct spi_master *spi_master; struct spi_device *spi_device; int status = 0; spi_master = spi_busnum_to_master(dev->spi_id); if (!spi_master) { dev_err(&dev->pdev->dev, "spi_busnum_to_master(%d) returned NULL\n", dev->spi_id); return -ENOSYS; } spi_device = spi_alloc_device(spi_master); if (!spi_device) { put_device(&spi_master->dev); dev_err(&dev->pdev->dev, "spi_alloc_device() failed\n"); return -ENOMEM; } spi_device->chip_select = 0; spi_device->max_speed_hz = 4000000; spi_device->mode = SPI_MODE_0; spi_device->bits_per_word = 8; spi_device->controller_data = (void *) dev->iCS; spi_device->dev.platform_data = dev; strlcpy(spi_device->modalias, SPI_DRIVER_NAME, sizeof(SPI_DRIVER_NAME)); status = spi_add_device(spi_device); if (status < 0) { spi_dev_put(spi_device); dev_err(&dev->pdev->dev, "spi_add_device() failed %d\n", status); return status; } dev->spi = spi_device; put_device(&spi_master->dev); return status; }
static int p3_disable_clk_cs(struct p3_dev *p3_device) { int ret_val = 0; //unsigned short clock = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; if (!p3_device->enabled_clk) { P3_ERR_MSG("%s - clock was not enabled!\n", __func__); return ret_val; } /* CS High */ gpio_set_value(p3_device->cs_gpio, 1); spin_lock_irq(&p3_device->ese_spi_lock); spidev = spi_dev_get(p3_device->spi); spin_unlock_irq(&p3_device->ese_spi_lock); if (spidev == NULL) { P3_ERR_MSG("%s - Failed to get spi dev!\n", __func__); return -1; } P3_DBG_MSG("%s DISABLE_SPI_CLOCK\n", __func__); sdd = spi_master_get_devdata(spidev->master); if (!sdd){ P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -EFAULT; } p3_device->enabled_clk = false; pm_runtime_put(&sdd->pdev->dev); spi_dev_put(spidev); return ret_val; }
static int p61_disable_clk(struct p61_dev *p61_device) { int ret_val = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; if (!p61_device->enabled_clk) { pr_err("%s - clock was not enabled!\n", __func__); return ret_val; } spin_lock_irq(&p61_device->ese_spi_lock); spidev = spi_dev_get(p61_device->spi); spin_unlock_irq(&p61_device->ese_spi_lock); if (spidev == NULL) { pr_err("%s - Failed to get spi dev!\n", __func__); return -1; } sdd = spi_master_get_devdata(spidev->master); if (!sdd) { pr_err("%s - Failed to get spi dev.\n", __func__); return -1; } p61_device->enabled_clk = false; pm_runtime_put(&sdd->pdev->dev); /* Disable clock */ spi_dev_put(spidev); //CS disable gpio_set_value(p61_device->cspin, 1); if (wake_lock_active(&p61_device->ese_lock)) { pr_info("%s: [NFC-ESE] wake unlock.\n", __func__); wake_unlock(&p61_device->ese_lock); } return ret_val; }
static int p3_enable_clk(struct p3_dev *p3_device) { int ret_val = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; /* for defence MULTI-OPEN */ if (p3_device->enabled_clk) { P3_ERR_MSG("%s - clock was ALREADY enabled!\n", __func__); return -EBUSY; } spin_lock_irq(&p3_device->ese_spi_lock); spidev = spi_dev_get(p3_device->spi); spin_unlock_irq(&p3_device->ese_spi_lock); if (spidev == NULL) { P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -1; } sdd = spi_master_get_devdata(spidev->master); if (!sdd){ P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -EFAULT; } pm_runtime_get_sync(&sdd->pdev->dev); /* Enable clk */ /* set spi clock rate */ clk_set_rate(sdd->src_clk, spidev->max_speed_hz * 2); #ifdef FEATURE_ESE_WAKELOCK wake_lock(&p3_device->ese_lock); #endif p3_device->enabled_clk = true; spi_dev_put(spidev); return ret_val; }
static int p61_set_clk(struct p61_dev *p61_device) { int ret_val = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; spin_lock_irq(&p61_device->ese_spi_lock); spidev = spi_dev_get(p61_device->spi); spin_unlock_irq(&p61_device->ese_spi_lock); if (spidev == NULL) { pr_err("%s - Failed to get spi dev\n", __func__); return -1; } spidev->max_speed_hz = P61_SPI_CLOCK; sdd = spi_master_get_devdata(spidev->master); if (!sdd) { pr_err("%s - Failed to get spi dev.\n", __func__); return -1; } pm_runtime_get_sync(&sdd->pdev->dev); /* Enable clk */ /* set spi clock rate */ clk_set_rate(sdd->src_clk, spidev->max_speed_hz * 2); p61_device->enabled_clk = true; spi_dev_put(spidev); //CS enable gpio_set_value(p61_device->cspin, 0); usleep_range(50, 70); if (!wake_lock_active(&p61_device->ese_lock)) { pr_info("%s: [NFC-ESE] wake lock.\n", __func__); wake_lock(&p61_device->ese_lock); } return ret_val; }
static int p3_disable_clk(struct p3_dev *p3_device) { int ret_val = 0; //unsigned short clock = 0; struct spi_device *spidev = NULL; struct s3c64xx_spi_driver_data *sdd = NULL; if (!p3_device->enabled_clk) { P3_ERR_MSG("%s - clock was not enabled!\n", __func__); return ret_val; } spin_lock_irq(&p3_device->ese_spi_lock); spidev = spi_dev_get(p3_device->spi); spin_unlock_irq(&p3_device->ese_spi_lock); if (spidev == NULL) { P3_ERR_MSG("%s - Failed to get spi dev!\n", __func__); return -1; } sdd = spi_master_get_devdata(spidev->master); if (!sdd){ P3_ERR_MSG("%s - Failed to get spi dev.\n", __func__); return -EFAULT; } p3_device->enabled_clk = false; pm_runtime_put_sync(&sdd->pdev->dev); /* Disable clock */ spi_dev_put(spidev); #ifdef FEATURE_ESE_WAKELOCK if (wake_lock_active(&p3_device->ese_lock)) wake_unlock(&p3_device->ese_lock); #endif return ret_val; }
static int cc2520_spi_add_to_bus(void) { struct spi_master *spi_master; struct spi_device *spi_device; struct device *pdev; char buff[64]; int status = 0; spi_master = spi_busnum_to_master(SPI_BUS); if (!spi_master) { printk(KERN_ALERT "[cc2520] - spi_busnum_to_master(%d) returned NULL\n", SPI_BUS); printk(KERN_ALERT "[cc2520] - Missing modprobe spi-bcm2708?\n"); return -1; } spi_device = spi_alloc_device(spi_master); if (!spi_device) { put_device(&spi_master->dev); printk(KERN_ALERT "[cc2520] - spi_alloc_device() failed\n"); return -1; } spi_device->chip_select = SPI_BUS_CS0; /* Check whether this SPI bus.cs is already claimed */ snprintf(buff, sizeof(buff), "%s.%u", dev_name(&spi_device->master->dev), spi_device->chip_select); pdev = bus_find_device_by_name(spi_device->dev.bus, NULL, buff); if (pdev) { if (pdev->driver != NULL) { printk(KERN_INFO "[cc2520] - Driver [%s] already registered for %s. Nuking from orbit.\n", pdev->driver->name, buff); } else { printk(KERN_INFO "[cc2520] - Previous driver registered with no loaded module. Nuking from orbit.\n"); } device_unregister(pdev); } spi_device->max_speed_hz = SPI_BUS_SPEED; spi_device->mode = SPI_MODE_0; spi_device->bits_per_word = 8; spi_device->irq = -1; spi_device->controller_state = NULL; spi_device->controller_data = NULL; strlcpy(spi_device->modalias, cc2520_name, SPI_NAME_SIZE); status = spi_add_device(spi_device); if (status < 0) { spi_dev_put(spi_device); printk(KERN_ALERT "[cc2520] - spi_add_device() failed: %d\n", status); } put_device(&spi_master->dev); return status; }
void of_register_spi_devices(struct spi_master *master, struct device_node *np) { struct spi_device *spi; struct device_node *nc; const __be32 *prop; int rc; int len; for_each_child_of_node(np, nc) { /* Alloc an spi_device */ spi = spi_alloc_device(master); if (!spi) { dev_err(&master->dev, "spi_device alloc error for %s\n", nc->full_name); spi_dev_put(spi); continue; } /* Select device driver */ if (of_modalias_node(nc, spi->modalias, sizeof(spi->modalias)) < 0) { dev_err(&master->dev, "cannot find modalias for %s\n", nc->full_name); spi_dev_put(spi); continue; } /* Device address */ prop = of_get_property(nc, "reg", &len); if (!prop || len < sizeof(*prop)) { dev_err(&master->dev, "%s has no 'reg' property\n", nc->full_name); spi_dev_put(spi); continue; } spi->chip_select = be32_to_cpup(prop); /* Mode (clock phase/polarity/etc.) */ if (of_find_property(nc, "spi-cpha", NULL)) spi->mode |= SPI_CPHA; if (of_find_property(nc, "spi-cpol", NULL)) spi->mode |= SPI_CPOL; if (of_find_property(nc, "spi-cs-high", NULL)) spi->mode |= SPI_CS_HIGH; /* Device speed */ prop = of_get_property(nc, "spi-max-frequency", &len); if (!prop || len < sizeof(*prop)) { dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n", nc->full_name); spi_dev_put(spi); continue; } spi->max_speed_hz = be32_to_cpup(prop); /* IRQ */ spi->irq = irq_of_parse_and_map(nc, 0); /* Store a pointer to the node in the device structure */ of_node_get(nc); spi->dev.of_node = nc; /* Register the new device */ request_module(spi->modalias); rc = spi_add_device(spi); if (rc) { dev_err(&master->dev, "spi_device register error %s\n", nc->full_name); spi_dev_put(spi); } }
static int __init add_pcd8544_device_to_bus(void) { struct spi_master *spi_master; struct spi_device *spi_device; struct device *pdev; char buff[64]; int status = 0; spi_master = spi_busnum_to_master(SPI_BUS); if (!spi_master) { printk(KERN_ALERT "spi_busnum_to_master(%d) returned NULL\n", SPI_BUS); printk(KERN_ALERT "Missing modprobe omap2_mcspi?\n"); return -1; } spi_device = spi_alloc_device(spi_master); if (!spi_device) { put_device(&spi_master->dev); printk(KERN_ALERT "spi_alloc_device() failed\n"); return -1; } spi_device->chip_select = SPI_BUS_CS; /* Check whether this SPI bus.cs is already claimed */ snprintf(buff, sizeof(buff), "%s.%u", dev_name(&spi_device->master->dev), spi_device->chip_select); pdev = bus_find_device_by_name(spi_device->dev.bus, NULL, buff); if (pdev) { /* We are not going to use this spi_device, so free it */ spi_dev_put(spi_device); /* * There is already a device configured for this bus.cs * It is okay if it us, otherwise complain and fail. */ if (pdev->driver && pdev->driver->name && strcmp(this_driver_name, pdev->driver->name)) { printk(KERN_ALERT "Driver [%s] already registered for %s\n", pdev->driver->name, buff); status = -1; } } else { spi_device->max_speed_hz = SPI_BUS_SPEED; spi_device->mode = SPI_MODE_0; spi_device->bits_per_word = 8; spi_device->irq = -1; spi_device->controller_state = NULL; spi_device->controller_data = NULL; strlcpy(spi_device->modalias, this_driver_name, SPI_NAME_SIZE); status = spi_add_device(spi_device); if (status < 0) { spi_dev_put(spi_device); printk(KERN_ALERT "spi_add_device() failed: %d\n", status); } } put_device(&spi_master->dev); return status; }
static int __init add_nxtts_device_to_bus(void) { struct spi_master *spi_master; struct spi_device *spi_device; struct device *pdev; char buff[64]; int status = 0; /* This call returns a refcounted pointer to the relevant spi_master - the caller must release this pointer(device_put()) */ spi_master = spi_busnum_to_master(SPI_BUS); if (!spi_master) { printk(KERN_ALERT "spi_busnum_to_master(%d) returned NULL\n", SPI_BUS); printk(KERN_ALERT "Missing modprobe omap2_mcspi?\n"); return -1; } spi_device = spi_alloc_device(spi_master); if (!spi_device) { printk(KERN_ALERT "spi_alloc_device() failed\n"); return -1; } spi_device->chip_select = SPI_BUS_CS0; /* Check whether this SPI bus.cs is already claimed */ /* snprintf the c-way of formatting a string */ snprintf(buff, sizeof(buff), "%s.%u", dev_name(&spi_device->master->dev), spi_device->chip_select); pdev = bus_find_device_by_name(spi_device->dev.bus, NULL, buff); if (pdev) { /* We are not going to use this spi_device, so free it. Since spi_device is not added then decrement the refcount */ spi_dev_put(spi_device); /* * There is already a device configured for this bus.cs * It is okay if it us, otherwise complain and fail. */ if (pdev->driver && pdev->driver->name && strcmp(DEVICE_NAME, pdev->driver->name)) { printk(KERN_ALERT "Driver [%s] already registered for %s\n", pdev->driver->name, buff); status = -1; } } else { spi_device->max_speed_hz = SPI_BUS_SPEED; spi_device->mode = SPI_MODE_0; spi_device->bits_per_word = SPI_BITS_PER_WORD; spi_device->irq = -1; spi_device->controller_state = NULL; spi_device->controller_data = NULL; strlcpy(spi_device->modalias, DEVICE_NAME, SPI_NAME_SIZE); status = spi_add_device(spi_device); if (status < 0) { /* If spi_device is not added then decrement the refcount */ spi_dev_put(spi_device); printk(KERN_ALERT "spi_add_device() failed: %d\n", status); } } /* See comment for spi_busnum_to_master */ put_device(&spi_master->dev); return status; }