Exemplo n.º 1
0
static int __devinit wl1271_probe(struct spi_device *spi)
{
	struct wl12xx_platform_data *pdata;
	struct ieee80211_hw *hw;
	struct wl1271 *wl;
	int ret;

	pdata = spi->dev.platform_data;
	if (!pdata) {
		wl1271_error("no platform data");
		return -ENODEV;
	}

	hw = wl1271_alloc_hw();
	if (IS_ERR(hw))
		return PTR_ERR(hw);

	wl = hw->priv;

	dev_set_drvdata(&spi->dev, wl);
	wl->if_priv = spi;

	wl->if_ops = &spi_ops;

	/* This is the only SPI value that we need to set here, the rest
	 * comes from the board-peripherals file */
	spi->bits_per_word = 32;

	ret = spi_setup(spi);
	if (ret < 0) {
		wl1271_error("spi_setup failed");
		goto out_free;
	}

	wl->set_power = pdata->set_power;
	if (!wl->set_power) {
		wl1271_error("set power function missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

	wl->ref_clock = pdata->board_ref_clock;

	wl->irq = spi->irq;
	if (wl->irq < 0) {
		wl1271_error("irq missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
	ret = compat_request_threaded_irq(&wl->irq_compat, wl->irq,
					  wl1271_hardirq, wl1271_irq,
					  IRQF_TRIGGER_RISING,
					  DRIVER_NAME, wl);
#else
	ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
				   IRQF_TRIGGER_RISING,
#else
				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
#endif
				   DRIVER_NAME, wl);
#endif
	if (ret < 0) {
		wl1271_error("request_irq() failed: %d", ret);
		goto out_free;
	}

	disable_irq(wl->irq);

	ret = wl1271_init_ieee80211(wl);
	if (ret)
		goto out_irq;

	ret = wl1271_register_hw(wl);
	if (ret)
		goto out_irq;

	wl1271_notice("initialized");

	return 0;

 out_irq:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
	compat_free_threaded_irq(&wl->irq_compat);
#else
	free_irq(wl->irq, wl);
#endif

 out_free:
	wl1271_free_hw(wl);

	return ret;
}
void dc_electronic_load_setup() {
  setCurrentMilliamps = 0;
  readCurrentMilliamps = 0;
  readMilliVolts = 0;
  setRateIndex = 0;
  readCurrentMilliampsDisplay = DISPLAY_MILLI;
  gfxState = GFX_STATE_MEASURE;

  dma_ring_buffer_init(&g_debugUsartDmaInputRingBuffer, DEBUG_USART_RX_DMA_CH, g_debugUsartRxBuffer, DEBUG_USART_RX_BUFFER_SIZE);

  debug_setup();
  debug_write_line("?BEGIN setup");

  process_init();
  process_start(&etimer_process, NULL);

  process_start(&debug_process, NULL);
#ifdef DISP6800_ENABLE
  process_start(&gfx_update_process, NULL);
  process_poll(&gfx_update_process);
#endif

  spi_setup();

#ifdef DISP6800_ENABLE
  disp6800_setup();
  gfx_setup();
#endif

#ifdef ENCODER_ENABLE
  encoder_setup();
#endif

#ifdef FLASH_ENABLE
  flashsst25_setup();
#endif

#ifdef MAC_ENABLE
  mac25aa02e48_setup();
  mac25aa02e48_read_eui48();
#endif

#ifdef ADC_ENABLE
  adc_setup();
#endif

#ifdef DAC_ENABLE
  dac_setup();
  dac_set(0);
#endif

#ifdef NETWORK_ENABLE
  network_setup(EUI48);
#endif

#ifdef FAN_ENABLE
  fan_setup();
#endif

#ifdef BUTTONS_ENABLE
  buttons_setup();
#endif

  time_setup();
  recorder_setup();

  debug_write_line("?END setup");
}
Exemplo n.º 3
0
static int ssp_probe(struct spi_device *spi_dev)
{
	int iRet = 0;
	struct ssp_data *data;
	struct ssp_platform_data *pdata;

	if (poweroff_charging == 1 || recovery_mode == 1) {
		pr_err("[SSP] probe exit : lpm %d recovery %d \n",
			poweroff_charging, recovery_mode);
		return -ENODEV;
	}

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL) {
		pr_err("[SSP]: %s - failed to allocate memory for data\n",
			__func__);
		iRet = -ENOMEM;
		goto exit;
	}

	if (spi_dev->dev.of_node) {
		iRet = ssp_parse_dt(&spi_dev->dev, data);
		if (iRet) {
			pr_err("[SSP]: %s - Failed to parse DT\n", __func__);
			goto err_setup;
		}
		data->ssp_changes = SSP_MCU_L5; /* K330, MPU L5*/
	} else {
		pdata = spi_dev->dev.platform_data;
		if (pdata == NULL) {
			pr_err("[SSP]: %s - platform_data is null\n", __func__);
			iRet = -ENOMEM;
			goto err_setup;
		}
		data->wakeup_mcu = pdata->wakeup_mcu;
		data->check_mcu_ready = pdata->check_mcu_ready;
		data->check_mcu_busy = pdata->check_mcu_busy;
		data->set_mcu_reset = pdata->set_mcu_reset;
		data->read_chg = pdata->read_chg;

		/* AP system_rev */
		if (pdata->check_ap_rev)
			data->ap_rev = pdata->check_ap_rev();
		else
			data->ap_rev = 0;
		/* For changed devices */
		if (pdata->check_changes)
			data->ssp_changes = pdata->check_changes();
		else
			data->ssp_changes = SSP_MCU_L5; /* K330, MPU L5*/

		/* Get sensor positions */
		if (pdata->get_positions)
			pdata->get_positions(&data->accel_position,
				&data->mag_position);
		else if (spi_dev->dev.of_node == NULL) {
			data->accel_position = 0;
			data->mag_position = 0;
		}

	}
	spi_dev->mode = SPI_MODE_1;
	if (spi_setup(spi_dev)) {
		pr_err("failed to setup spi for ssp_spi\n");
		goto err_setup;
	}

	data->bProbeIsDone = false;
	data->fw_dl_state = FW_DL_STATE_NONE;
	data->spi = spi_dev;
	spi_set_drvdata(spi_dev, data);

#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_init(&data->cp_temp_adc_lock);
	mutex_init(&data->bulk_temp_read_lock);
#endif
#ifdef CONFIG_SENSORS_SSP_STM
	mutex_init(&data->comm_mutex);
	mutex_init(&data->pending_mutex);
#endif

	if (((data->wakeup_mcu == NULL)
		|| (data->check_mcu_ready == NULL)
		|| (data->check_mcu_busy == NULL)
		|| (data->set_mcu_reset == NULL)
		|| (data->read_chg == NULL))
		&& (spi_dev->dev.of_node == NULL)) {
		pr_err("[SSP]: %s - function callback is null\n", __func__);
		iRet = -EIO;
		goto err_reset_null;
	}

	pr_info("\n#####################################################\n");

	INIT_DELAYED_WORK(&data->work_firmware, work_function_firmware_update);

	wake_lock_init(&data->ssp_wake_lock,
		WAKE_LOCK_SUSPEND, "ssp_wake_lock");

	iRet = initialize_input_dev(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create input device\n", __func__);
		goto err_input_register_device;
	}

	iRet = initialize_debug_timer(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}

	iRet = initialize_irq(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create irq\n", __func__);
		goto err_setup_irq;
	}

	iRet = initialize_sysfs(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create sysfs\n", __func__);
		goto err_sysfs_create;
	}

	iRet = initialize_event_symlink(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create symlink\n", __func__);
		goto err_symlink_create;
	}

	initialize_variable(data);
	
	ssp_enable(data, true);
	/* check boot loader binary */
	data->fw_dl_state = check_fwbl(data);

	if (data->fw_dl_state == FW_DL_STATE_NONE) {
		iRet = initialize_mcu(data);
		if (iRet == ERROR) {
			data->uResetCnt++;
			toggle_mcu_reset(data);
			msleep(SSP_SW_RESET_TIME);
			initialize_mcu(data);
		} else if (iRet < ERROR) {
			pr_err("[SSP]: %s - initialize_mcu failed\n", __func__);
			goto err_read_reg;
		}
	}

#ifdef CONFIG_HAS_EARLYSUSPEND
	data->early_suspend.suspend = ssp_early_suspend;
	data->early_suspend.resume = ssp_late_resume;
	register_early_suspend(&data->early_suspend);
#endif

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	/* init sensorhub device */
	iRet = ssp_sensorhub_initialize(data);
	if (iRet < 0) {
		pr_err("%s: ssp_sensorhub_initialize err(%d)", __func__, iRet);
		ssp_sensorhub_remove(data);
	}
#endif

	data->bMcuDumpMode = sec_debug_is_enabled();
	iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,data->bMcuDumpMode);
	if (iRet < 0) {
		pr_err("[SSP]: %s - MSG2SSP_AP_MCU_SET_DUMPMODE failed\n", __func__);
	}

	pr_info("[SSP]: %s - setup debuglevel %d!\n", __func__,data->bMcuDumpMode);


	pr_info("[SSP]: %s - probe success!\n", __func__);

	enable_debug_timer(data);

	iRet = 0;
	if (data->fw_dl_state == FW_DL_STATE_NEED_TO_SCHEDULE) {
		pr_info("[SSP]: Firmware update is scheduled\n");
		schedule_delayed_work(&data->work_firmware,
				msecs_to_jiffies(1000));
		data->fw_dl_state = FW_DL_STATE_SCHEDULED;
	} else if (data->fw_dl_state == FW_DL_STATE_FAIL)
		data->bSspShutdown = true;
	data->bProbeIsDone = true;

	goto exit;

err_read_reg:
err_symlink_create:
	remove_sysfs(data);
err_sysfs_create:
	free_irq(data->iIrq, data);
	gpio_free(data->mcu_int1);
err_setup_irq:
	destroy_workqueue(data->debug_wq);
err_create_workqueue:
	remove_input_dev(data);
err_input_register_device:
	wake_lock_destroy(&data->ssp_wake_lock);
err_reset_null:
#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_destroy(&data->cp_temp_adc_lock);
	mutex_destroy(&data->bulk_temp_read_lock);
#endif
#ifdef CONFIG_SENSORS_SSP_STM
	mutex_destroy(&data->comm_mutex);
	mutex_destroy(&data->pending_mutex);
#endif

err_setup:
	kfree(data);
	pr_err("[SSP]: %s - probe failed!\n", __func__);
exit:
	pr_info("#####################################################\n\n");
	return iRet;
}
int tdmb_fc8050_spi_write_read(uint8* tx_data, int tx_length, uint8 *rx_data, int rx_length)
{
	int rc;

	struct spi_transfer	t = {
			.tx_buf		= tx_data,
			.rx_buf		= rx_data,
			.len		= tx_length+rx_length,
		};

	struct spi_message	m;	

	if (fc8050_ctrl_info.spi_ptr == NULL)
	{
		printk("tdmb_fc8050_spi_write_read error txdata=0x%x, length=%d\n", (unsigned int)tx_data, tx_length+rx_length);
	}

	mutex_lock(&fc8050_ctrl_info.mutex);

	spi_message_init(&m);
	spi_message_add_tail(&t, &m);
	rc = spi_sync(fc8050_ctrl_info.spi_ptr, &m);
	if ( rc < 0 )
	{
		printk("tdmb_fc8050_spi_read_burst result(%d), actual_len=%d\n",rc, m.actual_length);
	}

	mutex_unlock(&fc8050_ctrl_info.mutex);

	return TRUE;
}

#ifdef FEATURE_DMB_USE_WORKQUEUE
static irqreturn_t broadcast_tdmb_spi_isr(int irq, void *handle)
{
	struct tdmb_fc8050_ctrl_blk* fc8050_info_p;
	unsigned long flag;

	fc8050_info_p = (struct tdmb_fc8050_ctrl_blk *)handle;	
	if ( fc8050_info_p && fc8050_info_p->TdmbPowerOnState )
	{
		if (fc8050_info_p->spi_irq_status)
		{			
			printk("######### spi read function is so late skip #########\n");			
			return IRQ_HANDLED;
		}		
//		printk("***** broadcast_tdmb_spi_isr coming *******\n");
		spin_lock_irqsave(&fc8050_info_p->spin_lock, flag);
		queue_work(fc8050_info_p->spi_wq, &fc8050_info_p->spi_work);
		spin_unlock_irqrestore(&fc8050_info_p->spin_lock, flag);    
	}
	else
	{
		printk("broadcast_tdmb_spi_isr is called, but device is off state\n");
	}

	return IRQ_HANDLED; 
}

static void broacast_tdmb_spi_work(struct work_struct *tdmb_work)
{
	struct tdmb_fc8050_ctrl_blk *pTdmbWorkData;

	pTdmbWorkData = container_of(tdmb_work, struct tdmb_fc8050_ctrl_blk, spi_work);
	if ( pTdmbWorkData )
	{
//		printk("broadcast_tdmb_spi_work START\n");
		fc8050_isr_control(0);
		pTdmbWorkData->spi_irq_status = TRUE;
		broadcast_drv_if_isr();
		pTdmbWorkData->spi_irq_status = FALSE;
		fc8050_isr_control(1);
//		printk("broadcast_tdmb_spi_work END\n");
//		printk("broacast_tdmb_spi_work is called handle=0x%x\n", (unsigned int)pTdmbWorkData);
	}
	else
	{
		printk("~~~~~~~broadcast_tdmb_spi_work call but pTdmbworkData is NULL ~~~~~~~\n");
	}
}
#else
static irqreturn_t broadcast_tdmb_spi_event_handler(int irq, void *handle)
{
	struct tdmb_fc8050_ctrl_blk *fc8050_info_p;

	fc8050_info_p = (struct tdmb_fc8050_ctrl_blk *)handle;
	if ( fc8050_info_p && fc8050_info_p->TdmbPowerOnState )
	{
		if (fc8050_info_p->spi_irq_status)
		{
			printk("######### spi read function is so late skip ignore #########\n");
			return IRQ_HANDLED;
		}

		fc8050_isr_control(0);
		fc8050_info_p->spi_irq_status = TRUE;
		broadcast_drv_if_isr();
		fc8050_info_p->spi_irq_status = FALSE;
		fc8050_isr_control(1);

	}
	else
	{
		printk("broadcast_tdmb_spi_isr is called, but device is off state\n");
	}
	return IRQ_HANDLED;
}
#endif

static int broadcast_tdmb_fc8050_probe(struct spi_device *spi)
{
	int rc;
	
#ifdef ANTENNA_SWITCHING
	struct pm_gpio GPIO11_CFG = {
				.direction      = PM_GPIO_DIR_OUT,
				.pull           = PM_GPIO_PULL_NO,
				.function       = PM_GPIO_FUNC_NORMAL,
				.vin_sel        = 2,	/* for ESD TEST in I-pjt */
				.inv_int_pol    = 0,	
				};
	struct pm_gpio GPIO12_CFG = {
				.direction      = PM_GPIO_DIR_OUT,
				.pull           = PM_GPIO_PULL_NO,
				.function       = PM_GPIO_FUNC_NORMAL,
				.vin_sel        = 2,	/* for ESD TEST in I-pjt */
				.inv_int_pol    = 0,			
				};	
#endif  /* ANTENNA_SWITCHING */        

	fc8050_ctrl_info.TdmbPowerOnState = FALSE;
	
	fc8050_ctrl_info.spi_ptr 				= spi;
	fc8050_ctrl_info.spi_ptr->mode 			= SPI_MODE_0;
	fc8050_ctrl_info.spi_ptr->bits_per_word 	= 8;
	fc8050_ctrl_info.spi_ptr->max_speed_hz 	= ( 24000*1000 );
	rc = spi_setup(spi);
	printk("broadcast_tdmb_fc8050_probe spi_setup=%d\n", rc);
	BBM_HOSTIF_SELECT(NULL, 1);
	
#ifdef FEATURE_DMB_USE_WORKQUEUE
	INIT_WORK(&fc8050_ctrl_info.spi_work, broacast_tdmb_spi_work);
	fc8050_ctrl_info.spi_wq = create_singlethread_workqueue("tdmb_spi_wq");
	if(fc8050_ctrl_info.spi_wq == NULL){
		printk("Failed to setup tdmb spi workqueue \n");
		return -ENOMEM;
	}
#endif
#ifdef FEATURE_DMB_USE_WORKQUEUE
	rc = request_irq(spi->irq, broadcast_tdmb_spi_isr, IRQF_DISABLED | IRQF_TRIGGER_FALLING, spi->dev.driver->name, &fc8050_ctrl_info);
#else
	rc = request_threaded_irq(spi->irq, NULL, broadcast_tdmb_spi_event_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING,
		spi->dev.driver->name, &fc8050_ctrl_info);
#endif
	printk("broadcast_tdmb_fc8050_probe request_irq=%d\n", rc);

	gpio_request(101, "DMB_RESET_N");
	gpio_request(102, "DMB_EN");
	gpio_request(107, "DMB_INT_N");
	gpio_direction_output(DMB_RESET_N, false);      
	gpio_direction_output(DMB_EN, false);               
	gpio_direction_output(DMB_INT_N, false);           

#ifdef ANTENNA_SWITCHING
	pm8xxx_gpio_config(DMB_ANT_SEL_P, &GPIO11_CFG);
	pm8xxx_gpio_config(DMB_ANT_SEL_N, &GPIO12_CFG);
	gpio_set_value_cansleep(DMB_ANT_SEL_P, 1);	/* for ESD TEST in I-pjt */
	gpio_set_value_cansleep(DMB_ANT_SEL_N, 0);	/* for ESD TEST in I-pjt */
#endif  /* ANTENNA_SWITCHING */
	tdmb_fc8050_interrupt_lock();

	mutex_init(&fc8050_ctrl_info.mutex);

	wake_lock_init(&fc8050_ctrl_info.wake_lock,  WAKE_LOCK_SUSPEND, dev_name(&spi->dev));		
	spin_lock_init(&fc8050_ctrl_info.spin_lock);

#ifdef PM_QOS
	pm_qos_add_request(&fc8050_ctrl_info.pm_req_list, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
#endif  /* PM_QOS */

	printk("broadcast_fc8050_probe End\n");

	return rc;
}

static int broadcast_tdmb_fc8050_remove(struct spi_device *spi)
{
	printk("broadcast_tdmb_fc8050_remove \n");
#ifdef FEATURE_DMB_USE_WORKQUEUE

	if (fc8050_ctrl_info.spi_wq)
	{
		flush_workqueue(fc8050_ctrl_info.spi_wq);
		destroy_workqueue(fc8050_ctrl_info.spi_wq);
	}
#endif
	free_irq(spi->irq, &fc8050_ctrl_info);

	mutex_destroy(&fc8050_ctrl_info.mutex);

	wake_lock_destroy(&fc8050_ctrl_info.wake_lock);

#ifdef PM_QOS
	pm_qos_remove_request(&fc8050_ctrl_info.pm_req_list);
#endif  /* PM_QOS */
	memset((unsigned char*)&fc8050_ctrl_info, 0x0, sizeof(struct tdmb_fc8050_ctrl_blk));
	return 0;
}

static int broadcast_tdmb_fc8050_suspend(struct spi_device *spi, pm_message_t mesg)
{
	printk("broadcast_tdmb_fc8050_suspend \n");
	return 0;
}
Exemplo n.º 5
0
static int tpo_td043_probe(struct spi_device *spi)
{
	struct panel_drv_data *ddata;
	struct omap_dss_device *dssdev;
	int r;

	dev_dbg(&spi->dev, "%s\n", __func__);

	spi->bits_per_word = 16;
	spi->mode = SPI_MODE_0;

	r = spi_setup(spi);
	if (r < 0) {
		dev_err(&spi->dev, "spi_setup failed: %d\n", r);
		return r;
	}

	ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
	if (ddata == NULL)
		return -ENOMEM;

	dev_set_drvdata(&spi->dev, ddata);

	ddata->spi = spi;

	if (!spi->dev.of_node)
		return -ENODEV;

	r = tpo_td043_probe_of(spi);
	if (r)
		return r;

	ddata->mode = TPO_R02_MODE_800x480;
	memcpy(ddata->gamma, tpo_td043_def_gamma, sizeof(ddata->gamma));

	ddata->vcc_reg = devm_regulator_get(&spi->dev, "vcc");
	if (IS_ERR(ddata->vcc_reg)) {
		dev_err(&spi->dev, "failed to get LCD VCC regulator\n");
		r = PTR_ERR(ddata->vcc_reg);
		goto err_regulator;
	}

	if (gpio_is_valid(ddata->nreset_gpio)) {
		r = devm_gpio_request_one(&spi->dev,
				ddata->nreset_gpio, GPIOF_OUT_INIT_LOW,
				"lcd reset");
		if (r < 0) {
			dev_err(&spi->dev, "couldn't request reset GPIO\n");
			goto err_gpio_req;
		}
	}

	r = sysfs_create_group(&spi->dev.kobj, &tpo_td043_attr_group);
	if (r) {
		dev_err(&spi->dev, "failed to create sysfs files\n");
		goto err_sysfs;
	}

	ddata->videomode = tpo_td043_timings;

	dssdev = &ddata->dssdev;
	dssdev->dev = &spi->dev;
	dssdev->driver = &tpo_td043_ops;
	dssdev->type = OMAP_DISPLAY_TYPE_DPI;
	dssdev->owner = THIS_MODULE;
	dssdev->panel.timings = ddata->videomode;

	r = omapdss_register_display(dssdev);
	if (r) {
		dev_err(&spi->dev, "Failed to register panel\n");
		goto err_reg;
	}

	return 0;

err_reg:
	sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group);
err_sysfs:
err_gpio_req:
err_regulator:
	omap_dss_put_device(ddata->in);
	return r;
}
static int __devinit p54spi_probe(struct spi_device *spi)
{
	struct p54s_priv *priv = NULL;
	struct ieee80211_hw *hw;
	int ret = -EINVAL;

	hw = p54_init_common(sizeof(*priv));
	if (!hw) {
		dev_err(&spi->dev, "could not alloc ieee80211_hw");
		return -ENOMEM;
	}

	priv = hw->priv;
	priv->hw = hw;
	dev_set_drvdata(&spi->dev, priv);
	priv->spi = spi;

	spi->bits_per_word = 16;
	spi->max_speed_hz = 24000000;

	ret = spi_setup(spi);
	if (ret < 0) {
		dev_err(&priv->spi->dev, "spi_setup failed");
		goto err_free_common;
	}

	ret = gpio_request(p54spi_gpio_power, "p54spi power");
	if (ret < 0) {
		dev_err(&priv->spi->dev, "power GPIO request failed: %d", ret);
		goto err_free_common;
	}

	ret = gpio_request(p54spi_gpio_irq, "p54spi irq");
	if (ret < 0) {
		dev_err(&priv->spi->dev, "irq GPIO request failed: %d", ret);
		goto err_free_common;
	}

	gpio_direction_output(p54spi_gpio_power, 0);
	gpio_direction_input(p54spi_gpio_irq);

	ret = request_irq(gpio_to_irq(p54spi_gpio_irq),
			  p54spi_interrupt, IRQF_DISABLED, "p54spi",
			  priv->spi);
	if (ret < 0) {
		dev_err(&priv->spi->dev, "request_irq() failed");
		goto err_free_common;
	}

	irq_set_irq_type(gpio_to_irq(p54spi_gpio_irq), IRQ_TYPE_EDGE_RISING);

	disable_irq(gpio_to_irq(p54spi_gpio_irq));

	INIT_WORK(&priv->work, p54spi_work);
	init_completion(&priv->fw_comp);
	INIT_LIST_HEAD(&priv->tx_pending);
	mutex_init(&priv->mutex);
	spin_lock_init(&priv->tx_lock);
	SET_IEEE80211_DEV(hw, &spi->dev);
	priv->common.open = p54spi_op_start;
	priv->common.stop = p54spi_op_stop;
	priv->common.tx = p54spi_op_tx;

	ret = p54spi_request_firmware(hw);
	if (ret < 0)
		goto err_free_common;

	ret = p54spi_request_eeprom(hw);
	if (ret)
		goto err_free_common;

	ret = p54_register_common(hw, &priv->spi->dev);
	if (ret)
		goto err_free_common;

	return 0;

err_free_common:
	p54_free_common(priv->hw);
	return ret;
}
Exemplo n.º 7
0
static int __devinit mc33880_probe(struct spi_device *spi)
{
	struct mc33880 *mc;
	struct mc33880_platform_data *pdata;
	int ret;

	pdata = spi->dev.platform_data;
	if (!pdata || !pdata->base) {
		dev_dbg(&spi->dev, "incorrect or missing platform data\n");
		return -EINVAL;
	}

	/*
	 * bits_per_word cannot be configured in platform data
	 */
	spi->bits_per_word = 8;

	ret = spi_setup(spi);
	if (ret < 0)
		return ret;

	mc = kzalloc(sizeof(struct mc33880), GFP_KERNEL);
	if (!mc)
		return -ENOMEM;

	mutex_init(&mc->lock);

	dev_set_drvdata(&spi->dev, mc);

	mc->spi = spi;

	mc->chip.label = DRIVER_NAME,
	mc->chip.set = mc33880_set;
	mc->chip.base = pdata->base;
	mc->chip.ngpio = PIN_NUMBER;
	mc->chip.can_sleep = 1;
	mc->chip.dev = &spi->dev;
	mc->chip.owner = THIS_MODULE;

	mc->port_config = 0x00;
	/* write twice, because during initialisation the first setting
	 * is just for testing SPI communication, and the second is the
	 * "real" configuration
	 */
	ret = mc33880_write_config(mc);
	mc->port_config = 0x00;
	if (!ret)
		ret = mc33880_write_config(mc);

	if (ret) {
		printk(KERN_ERR "Failed writing to " DRIVER_NAME ": %d\n", ret);
		goto exit_destroy;
	}

	ret = gpiochip_add(&mc->chip);
	if (ret)
		goto exit_destroy;

	return ret;

exit_destroy:
	dev_set_drvdata(&spi->dev, NULL);
	mutex_destroy(&mc->lock);
	kfree(mc);
	return ret;
}
static int broadcast_tdmb_fc8080_probe(struct spi_device *spi)
{
    int rc;

    if(spi == NULL)
    {
        printk("broadcast_fc8080_probe spi is NULL, so spi can not be set\n");
        return -1;
    }

    fc8080_ctrl_info.TdmbPowerOnState = FALSE;
    fc8080_ctrl_info.spi_ptr                 = spi;
    fc8080_ctrl_info.spi_ptr->mode             = SPI_MODE_0;
    fc8080_ctrl_info.spi_ptr->bits_per_word     = 8;
    fc8080_ctrl_info.spi_ptr->max_speed_hz     = (15000*1000);
    fc8080_ctrl_info.pdev = to_platform_device(&spi->dev);

#ifdef FEATURE_DMB_USE_BUS_SCALE
    fc8080_ctrl_info.bus_scale_pdata = msm_bus_cl_get_pdata(fc8080_ctrl_info.pdev);
    fc8080_ctrl_info.bus_scale_client_id = msm_bus_scale_register_client(fc8080_ctrl_info.bus_scale_pdata);
#endif

    // Once I have a spi_device structure I can do a transfer anytime

    rc = spi_setup(spi);
    printk("broadcast_tdmb_fc8080_probe spi_setup=%d\n", rc);
    bbm_com_hostif_select(NULL, 1);

#ifdef FEATURE_DMB_USE_XO
    fc8080_ctrl_info.clk = clk_get(&fc8080_ctrl_info.spi_ptr->dev, "xo");
    if (IS_ERR(fc8080_ctrl_info.clk)) {
        rc = PTR_ERR(fc8080_ctrl_info.clk);
        dev_err(&fc8080_ctrl_info.spi_ptr->dev, "could not get clock\n");
        return rc;
    }

    /* We enable/disable the clock only to assure it works */
    rc = clk_prepare_enable(fc8080_ctrl_info.clk);
    if (rc) {
        dev_err(&fc8080_ctrl_info.spi_ptr->dev, "could not enable clock\n");
        return rc;
    }
    clk_disable_unprepare(fc8080_ctrl_info.clk);
#endif

#ifdef FEATURE_DMB_USE_WORKQUEUE
    INIT_WORK(&fc8080_ctrl_info.spi_work, broacast_tdmb_spi_work);
    fc8080_ctrl_info.spi_wq = create_singlethread_workqueue("tdmb_spi_wq");
    if(fc8080_ctrl_info.spi_wq == NULL){
        printk("Failed to setup tdmb spi workqueue \n");
        return -ENOMEM;
    }
#endif

    tdmb_configure_gpios();

#ifdef FEATURE_DMB_USE_WORKQUEUE
    rc = request_irq(spi->irq, broadcast_tdmb_spi_isr, IRQF_DISABLED | IRQF_TRIGGER_FALLING,
                       spi->dev.driver->name, &fc8080_ctrl_info);
#else
    rc = request_threaded_irq(spi->irq, NULL, broadcast_tdmb_spi_event_handler, IRQF_ONESHOT | IRQF_DISABLED | IRQF_TRIGGER_FALLING,
                       spi->dev.driver->name, &fc8080_ctrl_info);
#endif
    printk("broadcast_tdmb_fc8080_probe request_irq=%d\n", rc);

    tdmb_fc8080_interrupt_lock();

    mutex_init(&fc8080_ctrl_info.mutex);

    wake_lock_init(&fc8080_ctrl_info.wake_lock,  WAKE_LOCK_SUSPEND, dev_name(&spi->dev));

    spin_lock_init(&fc8080_ctrl_info.spin_lock);

#ifdef FEATURE_DMB_USE_PM_QOS
    pm_qos_add_request(&fc8080_ctrl_info.pm_req_list, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
#endif
    printk("broadcast_fc8080_probe End\n");

    return rc;
}
int try_download_firmware(struct spich_data *spich)
{
	const struct firmware *fw_entry=NULL;

	uint8_t fw_header[STM_HEADER_SIZE+1]={0,};
	uint8_t stm_header[STM_HEADER_SIZE+1]={0,};
    int error=0;
    uint8_t FwHeaderExist=0x00;
    uint32_t header_offset=0;
    uint32_t FirmwareWriteOffset=0;
    uint8_t retry_cnt=0;

	spich_p = spich;
	spich->spi->mode = SPI_MODE_0;
	spich->spi->bits_per_word = 8;
//	spi->chip_select = 2;
	error = spi_setup(spich->spi);
    memset(fw_header,0x00,STM_HEADER_SIZE+1);
    memset(stm_header,0x00,STM_HEADER_SIZE+1);
	if(error < 0) {
		printk("STM spi setup fail  spi error = %d \n",error);
		return STM_SPI_SETUP_FAIL;
	}

	if(strlen(stm_inbuilt_fw_name_list) <= 0){
		return STM_FIRMWARE_NOT_EXIST;
    }
	error = request_firmware(&fw_entry,	stm_inbuilt_fw_name_list,&spich->spi->dev);
	if (error != 0) {
	    printk( "STM %s: Firmware image %s not available error=%d\n", __func__, stm_inbuilt_fw_name_list,error);
		return STM_FIRMWARE_NOT_EXIST;
	}
	printk( "STM Firmware image name = %s size = %zu\n",stm_inbuilt_fw_name_list, fw_entry->size);

    StmResetHub(STM_RESET);
    mdelay(spich->pre_reset_delay);
    StmResetHub(STM_SYSTEM);
    mdelay(spich->pre_reset_delay);

    Spi_Cs_Configuration(2);
    for(retry_cnt=0;retry_cnt < 12;retry_cnt++){
        if(communication_check()== STM_OK){
            break;
        }
        else{
            printk("AP-STM communication fail try = %dth\n",retry_cnt);
            StmResetHub(STM_RESET);
            mdelay(spich->pre_reset_delay);
            StmResetHub(STM_SYSTEM);
            mdelay(spich->pre_reset_delay);
        }
    }
    if(retry_cnt >= 12){
#if defined(STM_NOT_SLEEP)
	    StmResetHub(STM_SHUTDOWN);
#endif
        return STM_COMMUNICATION_FAIL;
    }
    FirmwareWriteOffset=0;
    header_offset = (fw_entry->size-STM_HEADER_SIZE);
    memcpy(fw_header,(fw_entry->data+header_offset),STM_HEADER_SIZE);
    printk("STM  fw header : %s\n",fw_header);


    if(firmware_header_check(fw_header) == STM_HEADER_EXIST){
        FwHeaderExist|=0x01;
        printk("STM firmware header exist !!!! \n");
    }

    StmFlashRead((STM_CODE_START_ADDRESS+header_offset),stm_header,STM_HEADER_SIZE);
    printk("STM stm header : %s\n",stm_header);
    if(firmware_header_check(stm_header) == STM_HEADER_EXIST){
        FwHeaderExist|=0x02;
        printk("STM stm header exist !!!! \n");
    }
#if defined(DONOT_DOWNLOAD_FIRMWARE)
#if defined(STM_NOT_SLEEP)
    StmResetHub(STM_SHUTDOWN);
#endif
	return STM_OK;
#endif
    switch(FwHeaderExist){
        case 0x00: /* both not exists */

        case 0x01: /* firmware header exist but stm NOT exist.  download the image and header*/
        case 0x02: /* firmware header NOT exist STM exist. download the image and erase header */
            printk("STM %d header NOT exist!!!\n",FwHeaderExist);
            StmErase(fw_entry->size+STM_HEADER_SIZE);
            StmFlashWrite(STM_CODE_START_ADDRESS,((uint8_t *)fw_entry->data+FirmwareWriteOffset),(uint32_t)fw_entry->size); //main code download
            break;
        case 0x03: /* Both Exists */
        {
            printk("STM both header exist!!!\n");
            if(strncmp(fw_header,stm_header, STM_HEADER_SIZE)!=0){ /*not same .download the image*/
                printk("STM you need to update STM firmware. download start.... erase start ");
                StmErase(fw_entry->size+STM_HEADER_SIZE);
                StmFlashWrite(STM_CODE_START_ADDRESS,((uint8_t *)fw_entry->data+FirmwareWriteOffset),(uint32_t)fw_entry->size);
            }
            else{
                printk("STM firmware is already latest version \n");
            }
            break;
        }
        default:
            printk("STM error %s(%d)\n",__func__,__LINE__);
            break;
        break;
    };

    Spi_Cs_Configuration(4);
#if !defined(STM_NOT_SLEEP)
	StmResetHub(STM_RESET);
#else
	StmResetHub(STM_SHUTDOWN);
#endif
    printk("STM download firmware done\n");

	if (fw_entry)
		release_firmware(fw_entry);

	return STM_OK;
}
Exemplo n.º 10
0
Arquivo: spi.c Projeto: AMouri/linux
static int __devinit wl1271_probe(struct spi_device *spi)
{
	struct wl12xx_platform_data *pdata;
	struct ieee80211_hw *hw;
	struct wl1271 *wl;
	unsigned long irqflags;
	int ret;

	pdata = spi->dev.platform_data;
	if (!pdata) {
		wl1271_error("no platform data");
		return -ENODEV;
	}

	hw = wl1271_alloc_hw();
	if (IS_ERR(hw))
		return PTR_ERR(hw);

	wl = hw->priv;

	dev_set_drvdata(&spi->dev, wl);
	wl->if_priv = spi;

	wl->if_ops = &spi_ops;

	/* This is the only SPI value that we need to set here, the rest
	 * comes from the board-peripherals file */
	spi->bits_per_word = 32;

	ret = spi_setup(spi);
	if (ret < 0) {
		wl1271_error("spi_setup failed");
		goto out_free;
	}

	wl->set_power = pdata->set_power;
	if (!wl->set_power) {
		wl1271_error("set power function missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

	wl->ref_clock = pdata->board_ref_clock;
	wl->tcxo_clock = pdata->board_tcxo_clock;
	wl->platform_quirks = pdata->platform_quirks;

	if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
		irqflags = IRQF_TRIGGER_RISING;
	else
		irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;

	wl->irq = spi->irq;
	if (wl->irq < 0) {
		wl1271_error("irq missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

	ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
				   irqflags,
				   DRIVER_NAME, wl);
	if (ret < 0) {
		wl1271_error("request_irq() failed: %d", ret);
		goto out_free;
	}

	disable_irq(wl->irq);

	ret = wl1271_init_ieee80211(wl);
	if (ret)
		goto out_irq;

	ret = wl1271_register_hw(wl);
	if (ret)
		goto out_irq;

	return 0;

 out_irq:
	free_irq(wl->irq, wl);

 out_free:
	wl1271_free_hw(wl);

	return ret;
}
Exemplo n.º 11
0
static int ds3234_probe(struct spi_device *spi)
{
	int res;
	unsigned int tmp;
	static const struct regmap_config config = {
		.reg_bits = 8,
		.val_bits = 8,
		.write_flag_mask = 0x80,
	};
	struct regmap *regmap;

	regmap = devm_regmap_init_spi(spi, &config);
	if (IS_ERR(regmap)) {
		dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
			__func__, PTR_ERR(regmap));
		return PTR_ERR(regmap);
	}

	spi->mode = SPI_MODE_3;
	spi->bits_per_word = 8;
	spi_setup(spi);

	res = regmap_read(regmap, DS3232_REG_SECONDS, &tmp);
	if (res)
		return res;

	/* Control settings
	 *
	 * CONTROL_REG
	 * BIT 7	6	5	4	3	2	1	0
	 *     EOSC	BBSQW	CONV	RS2	RS1	INTCN	A2IE	A1IE
	 *
	 *     0	0	0	1	1	1	0	0
	 *
	 * CONTROL_STAT_REG
	 * BIT 7	6	5	4	3	2	1	0
	 *     OSF	BB32kHz	CRATE1	CRATE0	EN32kHz	BSY	A2F	A1F
	 *
	 *     1	0	0	0	1	0	0	0
	 */
	res = regmap_read(regmap, DS3232_REG_CR, &tmp);
	if (res)
		return res;
	res = regmap_write(regmap, DS3232_REG_CR, tmp & 0x1c);
	if (res)
		return res;

	res = regmap_read(regmap, DS3232_REG_SR, &tmp);
	if (res)
		return res;
	res = regmap_write(regmap, DS3232_REG_SR, tmp & 0x88);
	if (res)
		return res;

	/* Print our settings */
	res = regmap_read(regmap, DS3232_REG_CR, &tmp);
	if (res)
		return res;
	dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp);

	res = regmap_read(regmap, DS3232_REG_SR, &tmp);
	if (res)
		return res;
	dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);

	return ds3232_probe(&spi->dev, regmap, spi->irq, "ds3234");
}

static struct spi_driver ds3234_driver = {
	.driver = {
		.name	 = "ds3234",
	},
	.probe	 = ds3234_probe,
};
Exemplo n.º 12
0
static int __devinit wl1271_probe(struct spi_device *spi)
{
	struct wl12xx_platform_data *pdata;
	struct ieee80211_hw *hw;
	struct wl1271 *wl;
	int ret, i;
	static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};

	pdata = spi->dev.platform_data;
	if (!pdata) {
		wl1271_error("no platform data");
		return -ENODEV;
	}

	hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
	if (!hw) {
		wl1271_error("could not alloc ieee80211_hw");
		return -ENOMEM;
	}

	wl = hw->priv;
	memset(wl, 0, sizeof(*wl));

	wl->hw = hw;
	dev_set_drvdata(&spi->dev, wl);
	wl->spi = spi;

	skb_queue_head_init(&wl->tx_queue);

	INIT_WORK(&wl->filter_work, wl1271_filter_work);
	wl->channel = WL1271_DEFAULT_CHANNEL;
	wl->scanning = false;
	wl->default_key = 0;
	wl->listen_int = 1;
	wl->rx_counter = 0;
	wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
	wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
	wl->elp = false;
	wl->psm = 0;
	wl->psm_requested = false;
	wl->tx_queue_stopped = false;
	wl->power_level = WL1271_DEFAULT_POWER_LEVEL;

	/* We use the default power on sleep time until we know which chip
	 * we're using */
	for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
		wl->tx_frames[i] = NULL;

	spin_lock_init(&wl->wl_lock);

	/*
	 * In case our MAC address is not correctly set,
	 * we use a random but Nokia MAC.
	 */
	memcpy(wl->mac_addr, nokia_oui, 3);
	get_random_bytes(wl->mac_addr + 3, 3);

	wl->state = WL1271_STATE_OFF;
	mutex_init(&wl->mutex);

	wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
	if (!wl->rx_descriptor) {
		wl1271_error("could not allocate memory for rx descriptor");
		ret = -ENOMEM;
		goto out_free;
	}

	/* This is the only SPI value that we need to set here, the rest
	 * comes from the board-peripherals file */
	spi->bits_per_word = 32;

	ret = spi_setup(spi);
	if (ret < 0) {
		wl1271_error("spi_setup failed");
		goto out_free;
	}

	wl->set_power = pdata->set_power;
	if (!wl->set_power) {
		wl1271_error("set power function missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

	wl->irq = spi->irq;
	if (wl->irq < 0) {
		wl1271_error("irq missing in platform data");
		ret = -ENODEV;
		goto out_free;
	}

	ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
	if (ret < 0) {
		wl1271_error("request_irq() failed: %d", ret);
		goto out_free;
	}

	set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);

	disable_irq(wl->irq);

	ret = platform_device_register(&wl1271_device);
	if (ret) {
		wl1271_error("couldn't register platform device");
		goto out_irq;
	}
	dev_set_drvdata(&wl1271_device.dev, wl);

	ret = wl1271_init_ieee80211(wl);
	if (ret)
		goto out_platform;

	ret = wl1271_register_hw(wl);
	if (ret)
		goto out_platform;

	wl1271_debugfs_init(wl);

	wl1271_notice("initialized");

	return 0;

 out_platform:
	platform_device_unregister(&wl1271_device);

 out_irq:
	free_irq(wl->irq, wl);

 out_free:
	kfree(wl->rx_descriptor);
	wl->rx_descriptor = NULL;

	ieee80211_free_hw(hw);

	return ret;
}
Exemplo n.º 13
0
static int pi433_probe(struct spi_device *spi)
{
	struct pi433_device	*device;
	int			retval;

	/* setup spi parameters */
	spi->mode = 0x00;
	spi->bits_per_word = 8;
	/*
	 * spi->max_speed_hz = 10000000;
	 * 1MHz already set by device tree overlay
	 */

	retval = spi_setup(spi);
	if (retval) {
		dev_dbg(&spi->dev, "configuration of SPI interface failed!\n");
		return retval;
	}

	dev_dbg(&spi->dev,
		"spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed",
		spi->mode, spi->bits_per_word, spi->max_speed_hz);

	/* Ping the chip by reading the version register */
	retval = spi_w8r8(spi, 0x10);
	if (retval < 0)
		return retval;

	switch (retval) {
	case 0x24:
		dev_dbg(&spi->dev, "found pi433 (ver. 0x%x)", retval);
		break;
	default:
		dev_dbg(&spi->dev, "unknown chip version: 0x%x", retval);
		return -ENODEV;
	}

	/* Allocate driver data */
	device = kzalloc(sizeof(*device), GFP_KERNEL);
	if (!device)
		return -ENOMEM;

	/* Initialize the driver data */
	device->spi = spi;
	device->rx_active = false;
	device->tx_active = false;
	device->interrupt_rx_allowed = false;

	/* init rx buffer */
	device->rx_buffer = kmalloc(MAX_MSG_SIZE, GFP_KERNEL);
	if (!device->rx_buffer) {
		retval = -ENOMEM;
		goto RX_failed;
	}

	/* init wait queues */
	init_waitqueue_head(&device->tx_wait_queue);
	init_waitqueue_head(&device->rx_wait_queue);
	init_waitqueue_head(&device->fifo_wait_queue);

	/* init fifo */
	INIT_KFIFO(device->tx_fifo);

	/* init mutexes and locks */
	mutex_init(&device->tx_fifo_lock);
	mutex_init(&device->rx_lock);

	/* setup GPIO (including irq_handler) for the different DIOs */
	retval = setup_gpio(device);
	if (retval) {
		dev_dbg(&spi->dev, "setup of GPIOs failed");
		goto GPIO_failed;
	}

	/* setup the radio module */
	retval = rf69_set_mode(spi, standby);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_set_data_mode(spi, DATAMODUL_MODE_PACKET);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_enable_amplifier(spi, MASK_PALEVEL_PA0);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA1);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA2);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_set_output_power_level(spi, 13);
	if (retval < 0)
		goto minor_failed;
	retval = rf69_set_antenna_impedance(spi, fifty_ohm);
	if (retval < 0)
		goto minor_failed;

	/* determ minor number */
	retval = pi433_get_minor(device);
	if (retval) {
		dev_dbg(&spi->dev, "get of minor number failed");
		goto minor_failed;
	}

	/* create device */
	device->devt = MKDEV(MAJOR(pi433_dev), device->minor);
	device->dev = device_create(pi433_class,
				    &spi->dev,
				    device->devt,
				    device,
				    "pi433.%d",
				    device->minor);
	if (IS_ERR(device->dev)) {
		pr_err("pi433: device register failed\n");
		retval = PTR_ERR(device->dev);
		goto device_create_failed;
	} else {
		dev_dbg(device->dev,
			"created device for major %d, minor %d\n",
			MAJOR(pi433_dev),
			device->minor);
	}

	/* start tx thread */
	device->tx_task_struct = kthread_run(pi433_tx_thread,
					     device,
					     "pi433.%d_tx_task",
					     device->minor);
	if (IS_ERR(device->tx_task_struct)) {
		dev_dbg(device->dev, "start of send thread failed");
		retval = PTR_ERR(device->tx_task_struct);
		goto send_thread_failed;
	}

	/* create cdev */
	device->cdev = cdev_alloc();
	if (!device->cdev) {
		dev_dbg(device->dev, "allocation of cdev failed");
		goto cdev_failed;
	}
	device->cdev->owner = THIS_MODULE;
	cdev_init(device->cdev, &pi433_fops);
	retval = cdev_add(device->cdev, device->devt, 1);
	if (retval) {
		dev_dbg(device->dev, "register of cdev failed");
		goto del_cdev;
	}

	/* spi setup */
	spi_set_drvdata(spi, device);

	return 0;

del_cdev:
	cdev_del(device->cdev);
cdev_failed:
	kthread_stop(device->tx_task_struct);
send_thread_failed:
	device_destroy(pi433_class, device->devt);
device_create_failed:
	pi433_free_minor(device);
minor_failed:
	free_gpio(device);
GPIO_failed:
	kfree(device->rx_buffer);
RX_failed:
	kfree(device);

	return retval;
}
Exemplo n.º 14
0
static int __devinit wl1271_probe(struct spi_device *spi)
{
	struct wl12xx_spi_glue *glue;
	struct wl12xx_platform_data *pdata;
	struct resource res[1];
	int ret = -ENOMEM;

	pdata = spi->dev.platform_data;
	if (!pdata) {
		dev_err(&spi->dev, "no platform data\n");
		return -ENODEV;
	}

	pdata->ops = &spi_ops;

	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
	if (!glue) {
		dev_err(&spi->dev, "can't allocate glue\n");
		goto out;
	}

	glue->dev = &spi->dev;

	spi_set_drvdata(spi, glue);

	/* This is the only SPI value that we need to set here, the rest
	 * comes from the board-peripherals file */
	spi->bits_per_word = 32;

	ret = spi_setup(spi);
	if (ret < 0) {
		dev_err(glue->dev, "spi_setup failed\n");
		goto out_free_glue;
	}

	glue->core = platform_device_alloc("wl12xx", -1);
	if (!glue->core) {
		dev_err(glue->dev, "can't allocate platform_device\n");
		ret = -ENOMEM;
		goto out_free_glue;
	}

	glue->core->dev.parent = &spi->dev;

	memset(res, 0x00, sizeof(res));

	res[0].start = spi->irq;
	res[0].flags = IORESOURCE_IRQ;
	res[0].name = "irq";

	ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
	if (ret) {
		dev_err(glue->dev, "can't add resources\n");
		goto out_dev_put;
	}

	ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
	if (ret) {
		dev_err(glue->dev, "can't add platform data\n");
		goto out_dev_put;
	}

	ret = platform_device_add(glue->core);
	if (ret) {
		dev_err(glue->dev, "can't register platform device\n");
		goto out_dev_put;
	}

	return 0;

out_dev_put:
	platform_device_put(glue->core);

out_free_glue:
	kfree(glue);
out:
	return ret;
}
Exemplo n.º 15
0
static int hx8357_probe(struct spi_device *spi)
{
	struct lcd_device *lcdev;
	struct hx8357_data *lcd;
	int i, ret;

	lcd = devm_kzalloc(&spi->dev, sizeof(*lcd), GFP_KERNEL);
	if (!lcd) {
		dev_err(&spi->dev, "Couldn't allocate lcd internal structure!\n");
		return -ENOMEM;
	}

	ret = spi_setup(spi);
	if (ret < 0) {
		dev_err(&spi->dev, "SPI setup failed.\n");
		return ret;
	}

	lcd->spi = spi;

	lcd->reset = of_get_named_gpio(spi->dev.of_node, "gpios-reset", 0);
	if (!gpio_is_valid(lcd->reset)) {
		dev_err(&spi->dev, "Missing dt property: gpios-reset\n");
		return -EINVAL;
	}

	ret = devm_gpio_request_one(&spi->dev, lcd->reset,
				    GPIOF_OUT_INIT_HIGH,
				    "hx8357-reset");
	if (ret) {
		dev_err(&spi->dev,
			"failed to request gpio %d: %d\n",
			lcd->reset, ret);
		return -EINVAL;
	}

	for (i = 0; i < HX8357_NUM_IM_PINS; i++) {
		lcd->im_pins[i] = of_get_named_gpio(spi->dev.of_node,
						"im-gpios", i);
		if (lcd->im_pins[i] == -EPROBE_DEFER) {
			dev_info(&spi->dev, "GPIO requested is not here yet, deferring the probe\n");
			return -EPROBE_DEFER;
		}
		if (!gpio_is_valid(lcd->im_pins[i])) {
			dev_err(&spi->dev, "Missing dt property: im-gpios\n");
			return -EINVAL;
		}

		ret = devm_gpio_request_one(&spi->dev, lcd->im_pins[i],
					GPIOF_OUT_INIT_LOW, "im_pins");
		if (ret) {
			dev_err(&spi->dev, "failed to request gpio %d: %d\n",
				lcd->im_pins[i], ret);
			return -EINVAL;
		}
	}

	lcdev = lcd_device_register("mxsfb", &spi->dev, lcd, &hx8357_ops);
	if (IS_ERR(lcdev)) {
		ret = PTR_ERR(lcdev);
		return ret;
	}
	spi_set_drvdata(spi, lcdev);

	ret = hx8357_lcd_init(lcdev);
	if (ret) {
		dev_err(&spi->dev, "Couldn't initialize panel\n");
		goto init_error;
	}

	dev_info(&spi->dev, "Panel probed\n");

	return 0;

init_error:
	lcd_device_unregister(lcdev);
	return ret;
}
Exemplo n.º 16
0
static int __init ws2401_dpi_spi_probe(struct spi_device *spi)
{
    int ret = 0;
    struct ws2401_dpi *lcd = container_of(spi->dev.driver,
                                          struct ws2401_dpi, spi_drv.driver);

    dev_dbg(&spi->dev, "panel ws2401_dpi spi being probed\n");

    dev_set_drvdata(&spi->dev, lcd);

    /* ws2401_dpi lcd panel uses 3-wire 9bits SPI Mode. */
    spi->bits_per_word = 9;

    ret = spi_setup(spi);
    if (ret < 0) {
        dev_err(&spi->dev, "spi setup failed.\n");
        goto out;
    }

    lcd->spi = spi;

    /*
     * if lcd panel was on from bootloader like u-boot then
     * do not lcd on.
     */
    if (!lcd->pd->platform_enabled) {
        /*
         * if lcd panel was off from bootloader then
         * current lcd status is powerdown and then
         * it enables lcd panel.
         */
        lcd->power = FB_BLANK_POWERDOWN;

        ws2401_dpi_power(lcd, FB_BLANK_UNBLANK);
    } else {
        lcd->power = FB_BLANK_UNBLANK;
        lcd->ldi_state = LDI_STATE_ON;
    }


#ifdef ESD_OPERATION
    lcd->esd_workqueue = create_singlethread_workqueue("esd_workqueue");

    if (!lcd->esd_workqueue) {
        dev_info(lcd->dev, "esd_workqueue create fail\n");
        return -ENOMEM;
    }

    INIT_WORK(&(lcd->esd_work), esd_work_func);

    lcd->esd_port = ESD_PORT_NUM;

    if (request_threaded_irq(GPIO_TO_IRQ(lcd->esd_port), NULL,
                             esd_interrupt_handler, IRQF_TRIGGER_RISING, "esd_interrupt", lcd)) {
        dev_info(lcd->dev, "esd irq request fail\n");
        free_irq(GPIO_TO_IRQ(lcd->esd_port), NULL);
        lcd->lcd_connected = 0;
    } else {
        /* low is normal. On PBA esd_port coule be HIGH */
        if (!gpio_get_value(lcd->esd_port)) {
            dev_info(lcd->dev, "esd irq enabled on booting\n");
            lcd->esd_enable = 1;
            lcd->lcd_connected = 1;
        } else {
            dev_info(lcd->dev, "esd irq disabled on booting\n");
            disable_irq(GPIO_TO_IRQ(lcd->esd_port));
            lcd->esd_enable = 0;
            lcd->lcd_connected = 0;
        }
    }

    dev_info(lcd->dev, "%s esd work success\n");

#ifdef ESD_TEST
    pdpi = lcd;
    setup_timer(&lcd->esd_test_timer, est_test_timer_func, 0);
    mod_timer(&lcd->esd_test_timer,  jiffies + (3*HZ));
#endif
#endif

    dev_dbg(&spi->dev, "ws2401_dpi spi has been probed.\n");

out:
    return ret;
}
Exemplo n.º 17
0
static int __devinit l4f00242t03_probe(struct spi_device *spi)
{
    struct l4f00242t03_priv *priv;
    struct l4f00242t03_pdata *pdata = spi->dev.platform_data;
    int ret;

    if (pdata == NULL) {
        dev_err(&spi->dev, "Uninitialized platform data.\n");
        return -EINVAL;
    }

    priv = kzalloc(sizeof(struct l4f00242t03_priv), GFP_KERNEL);

    if (priv == NULL) {
        dev_err(&spi->dev, "No memory for this device.\n");
        ret = -ENOMEM;
        goto err;
    }

    dev_set_drvdata(&spi->dev, priv);
    spi->bits_per_word = 9;
    spi_setup(spi);

    priv->spi = spi;

    ret = gpio_request(pdata->reset_gpio, "lcd l4f00242t03 reset");
    if (ret) {
        dev_err(&spi->dev,
                "Unable to get the lcd l4f00242t03 reset gpio.\n");
        return ret;
    }

    ret = gpio_direction_output(pdata->reset_gpio, 1);
    if (ret)
        goto err2;

    ret = gpio_request(pdata->data_enable_gpio,
                       "lcd l4f00242t03 data enable");
    if (ret) {
        dev_err(&spi->dev,
                "Unable to get the lcd l4f00242t03 data en gpio.\n");
        return ret;
    }

    ret = gpio_direction_output(pdata->data_enable_gpio, 0);
    if (ret)
        goto err3;

    if (pdata->io_supply) {
        priv->io_reg = regulator_get(NULL, pdata->io_supply);

        if (IS_ERR(priv->io_reg)) {
            pr_err("%s: Unable to get the IO regulator\n",
                   __func__);
            goto err3;
        }
    }

    if (pdata->core_supply) {
        priv->core_reg = regulator_get(NULL, pdata->core_supply);

        if (IS_ERR(priv->core_reg)) {
            pr_err("%s: Unable to get the core regulator\n",
                   __func__);
            goto err4;
        }
    }

    priv->ld = lcd_device_register("l4f00242t03",
                                   &spi->dev, priv, &l4f_ops);
    if (IS_ERR(priv->ld)) {
        ret = PTR_ERR(priv->ld);
        goto err5;
    }

    /* Init the LCD */
    l4f00242t03_reset(pdata->reset_gpio);
    l4f00242t03_lcd_init(spi);
    l4f00242t03_lcd_power_set(priv->ld, 1);

    dev_info(&spi->dev, "Epson l4f00242t03 lcd probed.\n");

    return 0;

err5:
    if (priv->core_reg)
        regulator_put(priv->core_reg);
err4:
    if (priv->io_reg)
        regulator_put(priv->io_reg);
err3:
    gpio_free(pdata->data_enable_gpio);
err2:
    gpio_free(pdata->reset_gpio);
err:
    kfree(priv);

    return ret;
}
Exemplo n.º 18
0
static int ds1343_probe(struct spi_device *spi)
{
	struct ds1343_priv *priv;
	struct regmap_config config;
	unsigned int data;
	int res;

	memset(&config, 0, sizeof(config));
	config.reg_bits = 8;
	config.val_bits = 8;
	config.write_flag_mask = 0x80;

	priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	priv->spi = spi;
	mutex_init(&priv->mutex);

	/* RTC DS1347 works in spi mode 3 and
	 * its chip select is active high
	 */
	spi->mode = SPI_MODE_3 | SPI_CS_HIGH;
	spi->bits_per_word = 8;
	res = spi_setup(spi);
	if (res)
		return res;

	spi_set_drvdata(spi, priv);

	priv->map = devm_regmap_init_spi(spi, &config);

	if (IS_ERR(priv->map)) {
		dev_err(&spi->dev, "spi regmap init failed for rtc ds1343\n");
		return PTR_ERR(priv->map);
	}

	res = regmap_read(priv->map, DS1343_SECONDS_REG, &data);
	if (res)
		return res;

	regmap_read(priv->map, DS1343_CONTROL_REG, &data);
	data |= DS1343_INTCN;
	data &= ~(DS1343_EOSC | DS1343_A1IE | DS1343_A0IE);
	regmap_write(priv->map, DS1343_CONTROL_REG, data);

	regmap_read(priv->map, DS1343_STATUS_REG, &data);
	data &= ~(DS1343_OSF | DS1343_IRQF1 | DS1343_IRQF0);
	regmap_write(priv->map, DS1343_STATUS_REG, data);

	priv->rtc = devm_rtc_device_register(&spi->dev, "ds1343",
					&ds1343_rtc_ops, THIS_MODULE);
	if (IS_ERR(priv->rtc)) {
		dev_err(&spi->dev, "unable to register rtc ds1343\n");
		return PTR_ERR(priv->rtc);
	}

	priv->irq = spi->irq;

	if (priv->irq >= 0) {
		res = devm_request_threaded_irq(&spi->dev, spi->irq, NULL,
						ds1343_thread,
						IRQF_NO_SUSPEND | IRQF_ONESHOT,
						"ds1343", priv);
		if (res) {
			priv->irq = -1;
			dev_err(&spi->dev,
				"unable to request irq for rtc ds1343\n");
		} else {
			device_set_wakeup_capable(&spi->dev, 1);
		}
	}

	res = ds1343_sysfs_register(&spi->dev);
	if (res)
		dev_err(&spi->dev,
			"unable to create sysfs entries for rtc ds1343\n");

	return 0;
}
Exemplo n.º 19
0
static inline int mmc_cs_off(struct mmc_spi_host *host)
{
	/* chipselect will always be inactive after setup() */
	return spi_setup(host->spi);
}
Exemplo n.º 20
0
int ili9341_probe_spi(struct spi_device *spi)
{
	struct device *dev = &spi->dev;
	struct ili9341 *ili;
	struct fb_info *info;
	int ret = 0;

	/* verify we where given some information */
	
	ili = devm_kzalloc(&spi->dev, sizeof(struct ili9341), GFP_KERNEL);
	if (ili == NULL) {
		dev_err(dev, "no memory for device\n");
		return -ENOMEM;
	}
	ili->dev = dev;
	spi->mode = SPI_MODE_0;
	spi_setup(spi);

	spi_set_drvdata(spi, ili);
	dev_info(&spi->dev, "spi registered, item=0x%p\n", (void *)ili);

	ili->gpiodc = 16;
	gpio_request(ili->gpiodc, "ili9341 dc pin");
	gpio_direction_output(ili->gpiodc, 0);
	dev_info(&spi->dev, "gpio %i registered\n", ili->gpiodc);

	ili->gpiorst = 12;
	gpio_request(ili->gpiorst, "ili9341 reset pin");
	gpio_direction_output(ili->gpiorst, 0);
	dev_info(&spi->dev, "gpio %i registered\n", ili->gpiorst);

	ili->spi = spi;
	
	info = framebuffer_alloc(sizeof(struct ili9341), &spi->dev);
	if (!info) {
		ret = -ENOMEM;
		dev_err(&spi->dev,
			"%s: unable to framebuffer_alloc\n", __func__);
		goto out_item;
	}
	info->pseudo_palette = &ili->pseudo_palette;
	ili->info = info;
	info->par = ili;
	info->dev = &spi->dev;
	info->fbops = &ili9341_fbops;
	info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
	info->fix = ili9341_fix;
	info->var = ili9341_var;

	ret = ili9341_video_alloc(ili);
	if (ret) {
		dev_err(&spi->dev,
			"%s: unable to ili9341_video_alloc\n", __func__);
		goto out_info;
	}
	info->screen_base = (char __iomem *)ili->info->fix.smem_start;

	ret = ili9341_pages_alloc(ili);
	if (ret < 0) {
		dev_err(&spi->dev,
			"%s: unable to ili9341_pages_init\n", __func__);
		goto out_video;
	}

	info->fbdefio = &ili9341_defio;
	fb_deferred_io_init(info);

	ret = register_framebuffer(info);
	if (ret < 0) {
		dev_err(&spi->dev,
			"%s: unable to register_frambuffer\n", __func__);
		goto out_pages;
	}
	
	ili9341_init_chip(ili);
	ili9341_update_all(ili);

	return ret;

out_pages:
	ili9341_pages_free(ili);
out_video:
	ili9341_video_free(ili);
out_info:
	framebuffer_release(info);
out_item:
	kfree(ili);
	return ret;
}
Exemplo n.º 21
0
static int __devinit ezx_pcap_probe(struct spi_device *spi)
{
	struct pcap_platform_data *pdata = spi->dev.platform_data;
	struct pcap_chip *pcap;
	int i, adc_irq;
	int ret = -ENODEV;

	/* platform data is required */
	if (!pdata)
		goto ret;

	pcap = kzalloc(sizeof(*pcap), GFP_KERNEL);
	if (!pcap) {
		ret = -ENOMEM;
		goto ret;
	}

	mutex_init(&pcap->io_mutex);
	mutex_init(&pcap->adc_mutex);
	INIT_WORK(&pcap->isr_work, pcap_isr_work);
	INIT_WORK(&pcap->msr_work, pcap_msr_work);
	dev_set_drvdata(&spi->dev, pcap);

	/* setup spi */
	spi->bits_per_word = 32;
	spi->mode = SPI_MODE_0 | (pdata->config & PCAP_CS_AH ? SPI_CS_HIGH : 0);
	ret = spi_setup(spi);
	if (ret)
		goto free_pcap;

	pcap->spi = spi;

	/* setup irq */
	pcap->irq_base = pdata->irq_base;
	pcap->workqueue = create_singlethread_workqueue("pcapd");
	if (!pcap->workqueue) {
		ret = -ENOMEM;
		dev_err(&spi->dev, "can't create pcap thread\n");
		goto free_pcap;
	}

	/* redirect interrupts to AP, except adcdone2 */
	if (!(pdata->config & PCAP_SECOND_PORT))
		ezx_pcap_write(pcap, PCAP_REG_INT_SEL,
					(1 << PCAP_IRQ_ADCDONE2));

	/* setup irq chip */
	for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++) {
		irq_set_chip_and_handler(i, &pcap_irq_chip, handle_simple_irq);
		irq_set_chip_data(i, pcap);
#ifdef CONFIG_ARM
		set_irq_flags(i, IRQF_VALID);
#else
		irq_set_noprobe(i);
#endif
	}

	/* mask/ack all PCAP interrupts */
	ezx_pcap_write(pcap, PCAP_REG_MSR, PCAP_MASK_ALL_INTERRUPT);
	ezx_pcap_write(pcap, PCAP_REG_ISR, PCAP_CLEAR_INTERRUPT_REGISTER);
	pcap->msr = PCAP_MASK_ALL_INTERRUPT;

	irq_set_irq_type(spi->irq, IRQ_TYPE_EDGE_RISING);
	irq_set_handler_data(spi->irq, pcap);
	irq_set_chained_handler(spi->irq, pcap_irq_handler);
	irq_set_irq_wake(spi->irq, 1);

	/* ADC */
	adc_irq = pcap_to_irq(pcap, (pdata->config & PCAP_SECOND_PORT) ?
					PCAP_IRQ_ADCDONE2 : PCAP_IRQ_ADCDONE);

	ret = request_irq(adc_irq, pcap_adc_irq, 0, "ADC", pcap);
	if (ret)
		goto free_irqchip;

	/* setup subdevs */
	for (i = 0; i < pdata->num_subdevs; i++) {
		ret = pcap_add_subdev(pcap, &pdata->subdevs[i]);
		if (ret)
			goto remove_subdevs;
	}

	/* board specific quirks */
	if (pdata->init)
		pdata->init(pcap);

	return 0;

remove_subdevs:
	device_for_each_child(&spi->dev, NULL, pcap_remove_subdev);
/* free_adc: */
	free_irq(adc_irq, pcap);
free_irqchip:
	for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++)
		irq_set_chip_and_handler(i, NULL, NULL);
/* destroy_workqueue: */
	destroy_workqueue(pcap->workqueue);
free_pcap:
	kfree(pcap);
ret:
	return ret;
}
Exemplo n.º 22
0
static int __devinit p61_probe(struct spi_device *spi)
{
	int ret = 0;
	struct p61_dev *p61_dev=NULL;
	unsigned int irq_flags;
	printk("P61 with irq without log Entry : %s\n", __FUNCTION__);

	NFC_DBG_MSG("chip select : %d , bus number = %d \n", spi->chip_select, spi->master->bus_num);
	p61_dev = kzalloc(sizeof(*p61_dev), GFP_KERNEL);
	if (p61_dev == NULL)
	{
		NFC_ERR_MSG("failed to allocate memory for module data\n");
		ret = -ENOMEM;
		goto err_exit;
	}
	
	ret = gpio_request( P61_RST, "p61 reset");
	if (ret < 0)
	{
		NFC_ERR_MSG("p61 gpio reset request failed = 0x%x\n", P61_RST);
		goto fail_gpio;
	}

	NFC_ERR_MSG("gpio_request returned = 0x%x\n", ret);
	ret = gpio_direction_output(P61_RST,0);
	if (ret < 0)
	{
		NFC_ERR_MSG("p61 gpio rst request failed gpio = 0x%x\n", P61_RST);
		goto fail_gpio;
	}
	NFC_ERR_MSG("gpio_direction_output returned = 0x%x\n", ret);

	
#ifdef IRQ_ENABLE
    	ret = gpio_request( P61_IRQ, "p61 irq");
    	if (ret < 0)
    	{
    		NFC_ERR_MSG("p61 gpio request failed gpio = 0x%x\n", P61_IRQ);
    		goto err_exit0;
    	}

    	ret = gpio_direction_input(P61_IRQ);
    	if (ret < 0)
    	{
    		NFC_ERR_MSG("p61 gpio request failed gpio = 0x%x\n", P61_IRQ);
    		goto err_exit0;
    	}
#endif

	spi->bits_per_word = 8;
	spi->mode = SPI_MODE_0;
	spi->max_speed_hz = 7000000;//1000000;
	//spi->chip_select = SPI_NO_CS;
	ret = spi_setup(spi);
	if (ret < 0)
	{
		NFC_ERR_MSG("failed to do spi_setup()\n");
		goto err_exit0;
	}

	p61_dev -> spi = spi;
	p61_dev -> p61_device.minor = MISC_DYNAMIC_MINOR;
	p61_dev -> p61_device.name = "p61";
	p61_dev -> p61_device.fops = &p61_dev_fops;
	p61_dev -> p61_device.parent = &spi->dev;

	p61_dev -> ven_gpio = P61_RST;
	
	gpio_set_value(P61_RST, 1);
	msleep(20);
	printk("p61_dev->rst_gpio = %d\n ",P61_RST);
#ifdef IRQ_ENABLE
	p61_dev->irq_gpio = P61_IRQ;
#endif
	
	p61_set_data(spi, p61_dev);
	/* init mutex and queues */
	init_waitqueue_head(&p61_dev->read_wq);
	mutex_init(&p61_dev->read_mutex);
	//spin_lock_init(&p61_dev->irq_enabled_lock);
#ifdef IRQ_ENABLE
	spin_lock_init(&p61_dev->irq_enabled_lock);
#endif

	ret = misc_register(&p61_dev->p61_device);
	if (ret < 0)
	{
		NFC_ERR_MSG("misc_register failed! %d\n", ret);
		goto err_exit0;
	}
#ifdef IRQ_ENABLE
    p61_dev->spi->irq = gpio_to_irq(P61_IRQ);

    if ( p61_dev->spi->irq < 0)
    {
    	NFC_ERR_MSG("gpio_to_irq request failed gpio = 0x%x\n", P61_IRQ);
        goto err_exit0;
    }
    /* request irq.  the irq is set whenever the chip has data available
         * for reading.  it is cleared when all data has been read.
         */
    p61_dev->irq_enabled = true;
    irq_flags = IRQF_TRIGGER_RISING | IRQF_ONESHOT;

    ret = request_irq(p61_dev->spi->irq, p61_dev_irq_handler,
                          irq_flags, p61_dev -> p61_device.name, p61_dev);
    if (ret)
    {
        NFC_ERR_MSG("request_irq failed\n");
        goto err_exit0;
    }
    p61_disable_irq(p61_dev);

#endif

	NFC_DBG_MSG("Exit : %s\n", __FUNCTION__);

	return ret;

//	err_exit1:
//	misc_deregister(&p61_dev->p61_device);
	err_exit0:
	mutex_destroy(&p61_dev->read_mutex);
        if(p61_dev != NULL)
	kfree(p61_dev);
	fail_gpio:
	gpio_free(P61_RST);
	err_exit:
	return ret;
}
Exemplo n.º 23
0
static int __devinit cyttsp4_spi_probe(struct spi_device *spi)
{
	struct cyttsp4_spi *ts_spi;
	int rc = 0;
	struct device *dev = &spi->dev;
	const struct of_device_id *match;
	char const *adap_id;

	dev_dbg(dev, "%s: Probing ...\n", __func__);

	spi->bits_per_word = CY_SPI_BITS_PER_WORD;
	spi->mode = SPI_MODE_0;

	rc = spi_setup(spi);
	if (rc < 0) {
		dev_err(dev, "%s: SPI setup error %d\n", __func__, rc);
		return rc;
	}

	ts_spi = kzalloc(sizeof(*ts_spi), GFP_KERNEL);
	if (ts_spi == NULL) {
		dev_err(dev, "%s: Error, kzalloc\n", __func__);
		rc = -ENOMEM;
		goto error_alloc_data_failed;
	}

	match = of_match_device(of_match_ptr(cyttsp4_spi_of_match), dev);
	if (match) {
		rc = of_property_read_string(dev->of_node, "cy,adapter_id",
				&adap_id);
		if (rc) {
			dev_err(dev, "%s: OF error rc=%d\n", __func__, rc);
			goto error_free_data;
		}
		cyttsp4_devtree_register_devices(dev);
	} else {
		adap_id = dev_get_platdata(dev);
	}

	mutex_init(&ts_spi->lock);
	ts_spi->client = spi;
	ts_spi->id = (adap_id) ? adap_id : CYTTSP4_SPI_NAME;
	dev_set_drvdata(&spi->dev, ts_spi);

	dev_dbg(dev, "%s: add adap='%s' (CYTTSP4_SPI_NAME=%s)\n", __func__,
		ts_spi->id, CYTTSP4_SPI_NAME);

	pm_runtime_enable(&spi->dev);

	rc = cyttsp4_add_adapter(ts_spi->id, &ops, dev);
	if (rc) {
		dev_err(dev, "%s: Error on probe %s\n", __func__,
			CYTTSP4_SPI_NAME);
		goto add_adapter_err;
	}

	dev_info(dev, "%s: Successful prob %s\n", __func__, CYTTSP4_SPI_NAME);

	return 0;

add_adapter_err:
	pm_runtime_disable(&spi->dev);
	dev_set_drvdata(&spi->dev, NULL);
error_free_data:
	kfree(ts_spi);
error_alloc_data_failed:
	return rc;
}