Example #1
0
int tdmb_lg2102_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 (lg2102_ctrl_info.spi_ptr == NULL)
	{
		printk("tdmb_lg2102_spi_write_read error txdata=0x%x, length=%d\n", (unsigned int)tx_data, tx_length+rx_length);
		return FALSE;
	}

	mutex_lock(&lg2102_ctrl_info.mutex);

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

	mutex_unlock(&lg2102_ctrl_info.mutex);

	return TRUE;
}

static irqreturn_t broadcast_tdmb_spi_isr(int irq, void *handle)
{
	struct tdmb_lg2102_ctrl_blk* pTdmbInfo;
	unsigned long flag;

	pTdmbInfo = (struct tdmb_lg2102_ctrl_blk *)handle;	
	
	if ( pTdmbInfo && pTdmbInfo->TdmbPowerOnState )
	{
		if (pTdmbInfo->spi_irq_status)
		{
			printk("########### DMB SPI ISR but funtion is so late skip ###########\n");
			return IRQ_HANDLED;
		}
		spin_lock_irqsave(&pTdmbInfo->spin_lock, flag);
		queue_work(pTdmbInfo->spi_wq, &pTdmbInfo->spi_work);
		spin_unlock_irqrestore(&pTdmbInfo->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_lg2102_ctrl_blk *pTdmbWorkData;

	pTdmbWorkData = container_of(tdmb_work, struct tdmb_lg2102_ctrl_blk, spi_work);
	if ( pTdmbWorkData )
	{
		pTdmbWorkData->spi_irq_status = TRUE;
		broadcast_drv_if_read_data();
		pTdmbWorkData->spi_irq_status = FALSE;
	}
}

static int broadcast_tdmb_lg2102_probe(struct spi_device *spi)
{
	int rc;

	lg2102_ctrl_info.spi_ptr 					= spi;
	lg2102_ctrl_info.spi_ptr->mode 			= SPI_MODE_0;
	lg2102_ctrl_info.spi_ptr->bits_per_word 	= 8;
	lg2102_ctrl_info.spi_ptr->max_speed_hz 	= (6000*1000);

	lg2102_ctrl_info.spi_ptr->irq = TEGRA_GPIO_TO_IRQ(118);
	
	rc = spi_setup(spi);
	
	INIT_WORK(&lg2102_ctrl_info.spi_work, broacast_tdmb_spi_work);
	lg2102_ctrl_info.spi_wq = create_singlethread_workqueue("tdmb_spi_wq");
	if(lg2102_ctrl_info.spi_wq == NULL){
		printk("Failed to setup tdmb spi workqueue \n");          
	}

	gpio_request(DMB_RESET_N, "dmb reset");
	gpio_request(DMB_EN, "dmb enable");
	gpio_request(DMB_INT_N, "dmb interrupt");
	gpio_request(DMB_EARANT, "dmb earantenna");

	tegra_gpio_enable(DMB_INT_N);
	tegra_gpio_enable(DMB_RESET_N);
	tegra_gpio_enable(DMB_EN);
	tegra_gpio_enable(DMB_EARANT);

	// Setting the ON/OFF pin to output mode and setting to Low.
    gpio_direction_output(DMB_RESET_N, 0);
	gpio_direction_output(DMB_EN, 0);
	gpio_direction_output(DMB_EARANT, 0);

	gpio_set_value(DMB_RESET_N, 0);
	gpio_set_value(DMB_EN, 0);
	gpio_set_value(DMB_EARANT, 0);

	rc = request_irq(lg2102_ctrl_info.spi_ptr->irq, broadcast_tdmb_spi_isr,  IRQF_DISABLED|IRQF_TRIGGER_FALLING , lg2102_ctrl_info.spi_ptr->dev.driver->name, &lg2102_ctrl_info);
	printk("broadcast_tdmb_lg2102_probe request_irq=%d\n", rc);
			
	tdmb_lg2102_interrupt_lock();

	mutex_init(&lg2102_ctrl_info.mutex);
	wake_lock_init(&lg2102_ctrl_info.wake_lock,  WAKE_LOCK_SUSPEND, dev_name(&spi->dev));

	spin_lock_init(&lg2102_ctrl_info.spin_lock);
	pm_qos_add_request(&lg2102_ctrl_info.pm_req_list, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);

	printk("[lg2102_probe] probe complete");
	
	return rc;
}
static int __init diagchar_init(void)
{
	dev_t dev;
	int error;

	DIAG_INFO("diagfwd initializing ..\n");
	driver = kzalloc(sizeof(struct diagchar_dev) + 5, GFP_KERNEL);

	if (driver) {
		driver->used = 0;
		timer_in_progress = 0;
		driver->debug_flag = 1;
		setup_timer(&drain_timer, drain_timer_func, 1234);
		driver->itemsize = itemsize;
		driver->poolsize = poolsize;
		driver->itemsize_hdlc = itemsize_hdlc;
		driver->poolsize_hdlc = poolsize_hdlc;
		driver->itemsize_write_struct = itemsize_write_struct;
		driver->poolsize_write_struct = poolsize_write_struct;
		driver->num_clients = max_clients;
		driver->logging_mode = USB_MODE;
		mutex_init(&driver->diagchar_mutex);
		init_waitqueue_head(&driver->wait_q);
		wake_lock_init(&driver->wake_lock, WAKE_LOCK_SUSPEND, "diagchar");

		INIT_WORK(&(driver->diag_drain_work), diag_drain_work_fn);
		INIT_WORK(&(driver->diag_read_smd_work), diag_read_smd_work_fn);
		INIT_WORK(&(driver->diag_read_smd_cntl_work),
						 diag_read_smd_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_work),
			   diag_read_smd_qdsp_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_cntl_work),
			   diag_read_smd_qdsp_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_work),
			diag_read_smd_wcnss_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_cntl_work),
			diag_read_smd_wcnss_cntl_work_fn);
#ifdef CONFIG_DIAG_SDIO_PIPE
		driver->num_mdmclients = 1;
		init_waitqueue_head(&driver->mdmwait_q);
		spin_lock_init(&driver->diagchar_lock);
		mutex_init(&driver->diagcharmdm_mutex);

		driver->num = 2;
#else
		driver->num = 1;
#endif
		diagfwd_init();
		if (chk_config_get_id() == AO8960_TOOLS_ID) {
			diagfwd_cntl_init();
			DIAGFWD_INFO("CNTL channel was enabled in the platform\n");
		} else
			DIAGFWD_INFO("CNTL channel was not enabled in the platform\n");

		diag_sdio_fn(INIT);
		pr_debug("diagchar initializing ..\n");
		driver->name = ((void *)driver) + sizeof(struct diagchar_dev);
		strlcpy(driver->name, "diag", 4);

		/* Get major number from kernel and initialize */
		error = alloc_chrdev_region(&dev, driver->minor_start,
					    driver->num, driver->name);
		if (!error) {
			driver->major = MAJOR(dev);
			driver->minor_start = MINOR(dev);
		} else {
			printk(KERN_INFO "Major number not allocated\n");
			goto fail;
		}
		driver->cdev = cdev_alloc();

#ifdef CONFIG_DIAG_SDIO_PIPE
		driver->cdev_mdm = cdev_alloc();
#endif
		error = diagchar_setup_cdev(dev);
		if (error)
			goto fail;
	} else {
		printk(KERN_INFO "kzalloc failed\n");
		goto fail;
	}

	DIAG_INFO("diagchar initialized\n");
	return 0;

fail:
	diagchar_cleanup();
	diagfwd_exit();
	diagfwd_cntl_exit();
	diag_sdio_fn(EXIT);
	return -1;
}
Example #3
0
int init_module(void)
{
	int nRet, i;   /* initialized below */
	nRet = 0;

#ifdef IMPLEMENT_AS_CHAR_DRIVER
	printk(KERN_ERR
		"[VIBRATOR]IMPLEMENT_AS_CHAR_DRIVER\n");
	g_nMajor = register_chrdev(0, MODULE_NAME, &fops);
	if (g_nMajor < 0) {
		printk(KERN_ERR"[VIBRATOR]tspdrv: can't get major number.\n");
		return g_nMajor;
	}
#else
	nRet = misc_register(&miscdev);
	if (nRet) {
		printk(KERN_ERR "[VIBRATOR]tspdrv: misc_register failed.\n");
		return nRet;
	}
#endif

	nRet = platform_device_register(&platdev);
	if (nRet) {
		printk(KERN_ERR "tspdrv: platform_device_register failed.\n");
		goto err_platform_dev_reg;
	}

	nRet = platform_driver_register(&platdrv);
	if (nRet) {
		printk(KERN_ERR "tspdrv: platform_driver_register failed.\n");
		goto err_platform_drv_reg;
	}

	DbgRecorderInit(());

	nRet = vibetonz_clk_on(&platdev.dev);
	if (nRet) {
		DbgOut((KERN_ERR "tspdrv: failed to get clock for vibetonz\n"));
		goto err_clk0;
	}

	ImmVibeSPI_ForceOut_Initialize();
	VibeOSKernelLinuxInitTimer();

	/* Get and concatenate device name and initialize data buffer */
	g_cchDeviceName = 0;
	for (i = 0; i < NUM_ACTUATORS; i++) {
		char *szName = g_szDeviceName + g_cchDeviceName;
		ImmVibeSPI_Device_GetName(i, szName,
			VIBE_MAX_DEVICE_NAME_LENGTH);

		/* Append version information and get buffer length */
		strcat(szName, VERSION_STR);
		g_cchDeviceName += strlen(szName);

		g_SamplesBuffer[i].nIndexPlayingBuffer = -1; /* Not playing */
		g_SamplesBuffer[i].actuatorSamples[0].nBufferSize = 0;
		g_SamplesBuffer[i].actuatorSamples[1].nBufferSize = 0;
	}

	wake_lock_init(&vib_wake_lock, WAKE_LOCK_SUSPEND, "vib_present");
	return 0;

err_clk0:
err_platform_drv_reg:
	platform_device_unregister(&platdev);
err_platform_dev_reg:
#ifdef IMPLEMENT_AS_CHAR_DRIVER
	unregister_chrdev(g_nMajor, MODULE_NAME);
#else
	misc_deregister(&miscdev);
#endif
	return nRet;
}
static int __devinit ehci_msm2_probe(struct platform_device *pdev)
{
	struct usb_hcd *hcd;
	struct resource *res;
	struct msm_hcd *mhcd;
	const struct msm_usb_host_platform_data *pdata;
	char pdev_name[PDEV_NAME_LEN];
	int ret;

	dev_dbg(&pdev->dev, "ehci_msm2 probe\n");

	hcd = usb_create_hcd(&msm_hc2_driver, &pdev->dev,
				dev_name(&pdev->dev));
	if (!hcd) {
		dev_err(&pdev->dev, "Unable to create HCD\n");
		return  -ENOMEM;
	}

	hcd->irq = platform_get_irq(pdev, 0);
	if (hcd->irq < 0) {
		dev_err(&pdev->dev, "Unable to get IRQ resource\n");
		ret = hcd->irq;
		goto put_hcd;
	}

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
		dev_err(&pdev->dev, "Unable to get memory resource\n");
		ret = -ENODEV;
		goto put_hcd;
	}

	hcd->rsrc_start = res->start;
	hcd->rsrc_len = resource_size(res);
	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
	if (!hcd->regs) {
		dev_err(&pdev->dev, "ioremap failed\n");
		ret = -ENOMEM;
		goto put_hcd;
	}

	mhcd = hcd_to_mhcd(hcd);
	mhcd->dev = &pdev->dev;

	snprintf(pdev_name, PDEV_NAME_LEN, "%s.%d", pdev->name, pdev->id);
	mhcd->xo_handle = msm_xo_get(MSM_XO_TCXO_D0, pdev_name);
	if (IS_ERR(mhcd->xo_handle)) {
		dev_err(&pdev->dev, "%s not able to get the handle "
			"to vote for TCXO D0 buffer\n", __func__);
		ret = PTR_ERR(mhcd->xo_handle);
		goto unmap;
	}

	ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_ON);
	if (ret) {
		dev_err(&pdev->dev, "%s failed to vote for TCXO "
			"D0 buffer%d\n", __func__, ret);
		goto free_xo_handle;
	}

	ret = msm_ehci_init_clocks(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "unable to initialize clocks\n");
		ret = -ENODEV;
		goto devote_xo_handle;
	}

	ret = msm_ehci_init_vddcx(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "unable to initialize VDDCX\n");
		ret = -ENODEV;
		goto deinit_clocks;
	}

	ret = msm_ehci_config_vddcx(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "hsusb vddcx configuration failed\n");
		goto deinit_vddcx;
	}

	ret = msm_ehci_ldo_init(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "hsusb vreg configuration failed\n");
		goto deinit_vddcx;
	}

	ret = msm_ehci_ldo_enable(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "hsusb vreg enable failed\n");
		goto deinit_ldo;
	}

	ret = msm_ehci_init_vbus(mhcd, 1);
	if (ret) {
		dev_err(&pdev->dev, "unable to get vbus\n");
		goto disable_ldo;
	}

	ret = msm_hsusb_reset(mhcd);
	if (ret) {
		dev_err(&pdev->dev, "hsusb PHY initialization failed\n");
		goto vbus_deinit;
	}

	ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
	if (ret) {
		dev_err(&pdev->dev, "unable to register HCD\n");
		goto vbus_deinit;
	}

	pdata = mhcd->dev->platform_data;
	if (pdata && (!pdata->dock_connect_irq ||
				!irq_read_line(pdata->dock_connect_irq)))
		msm_ehci_vbus_power(mhcd, 1);

	device_init_wakeup(&pdev->dev, 1);
	wake_lock_init(&mhcd->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
	wake_lock(&mhcd->wlock);
	INIT_WORK(&mhcd->phy_susp_fail_work, msm_ehci_phy_susp_fail_work);
	/*
	 * This pdev->dev is assigned parent of root-hub by USB core,
	 * hence, runtime framework automatically calls this driver's
	 * runtime APIs based on root-hub's state.
	 */
	/* configure pmic_gpio_irq for D+ change */
	if (pdata && pdata->pmic_gpio_dp_irq)
		mhcd->pmic_gpio_dp_irq = pdata->pmic_gpio_dp_irq;
	if (mhcd->pmic_gpio_dp_irq) {
		ret = request_threaded_irq(mhcd->pmic_gpio_dp_irq, NULL,
				msm_ehci_host_wakeup_irq,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				"msm_ehci_host_wakeup", mhcd);
		if (!ret) {
			disable_irq_nosync(mhcd->pmic_gpio_dp_irq);
		} else {
			dev_err(&pdev->dev, "request_irq(%d) failed: %d\n",
					mhcd->pmic_gpio_dp_irq, ret);
			mhcd->pmic_gpio_dp_irq = 0;
		}
	} else if (pdata->mpm_xo_wakeup_int) {
		msm_mpm_set_pin_type(pdata->mpm_xo_wakeup_int,
					IRQ_TYPE_LEVEL_HIGH);
		msm_mpm_set_pin_wake(pdata->mpm_xo_wakeup_int, 1);
	}
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	if (ehci_debugfs_init(mhcd) < 0)
		dev_err(mhcd->dev, "%s: debugfs init failed\n", __func__);

	return 0;

vbus_deinit:
	msm_ehci_init_vbus(mhcd, 0);
disable_ldo:
	msm_ehci_ldo_enable(mhcd, 0);
deinit_ldo:
	msm_ehci_ldo_init(mhcd, 0);
deinit_vddcx:
	msm_ehci_init_vddcx(mhcd, 0);
deinit_clocks:
	msm_ehci_init_clocks(mhcd, 0);
devote_xo_handle:
	msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_OFF);
free_xo_handle:
	msm_xo_put(mhcd->xo_handle);
unmap:
	iounmap(hcd->regs);
put_hcd:
	usb_put_hcd(hcd);

	return ret;
}
Example #5
0
static int pn544_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	int ret;
	struct pn544_i2c_platform_data *platform_data;
	struct pn544_dev *pn544_dev;

	platform_data = client->dev.platform_data;

	if (platform_data == NULL) {
		pr_err("%s : nfc probe fail\n", __func__);
		return  -ENODEV;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s : need I2C_FUNC_I2C\n", __func__);
		return  -ENODEV;
	}

	ret = gpio_request(platform_data->irq_gpio, "nfc_int");
	if (ret)
		return  -ENODEV;

    ret = gpio_direction_input(platform_data->irq_gpio);
	if (ret)
		goto err_ven;

	ret = gpio_request(platform_data->ven_gpio, "nfc_ven");
	if (ret)
		goto err_ven;

    ret = gpio_direction_output(platform_data->ven_gpio, 0);		
    if (ret )
		goto err_firm;
    
	ret = gpio_request(platform_data->firm_gpio, "nfc_firm");
	if (ret)
		goto err_firm;

    ret = gpio_direction_output(platform_data->firm_gpio, 0);		
    if (ret )
		goto err_exit;

	pn544_dev = kzalloc(sizeof(*pn544_dev), GFP_KERNEL);
	if (pn544_dev == NULL) {
		dev_err(&client->dev,
				"failed to allocate memory for module data\n");
		ret = -ENOMEM;
		goto err_exit;
	}

	pn544_dev->irq_gpio = platform_data->irq_gpio;
	pn544_dev->ven_gpio  = platform_data->ven_gpio;
	pn544_dev->firm_gpio  = platform_data->firm_gpio;
	pn544_dev->client   = client;

	/* init mutex and queues */
	init_waitqueue_head(&pn544_dev->read_wq);
	mutex_init(&pn544_dev->read_mutex);
	spin_lock_init(&pn544_dev->irq_enabled_lock);
#if defined(NFC_RF_FIELD_ON_OFF_DETECTED)
	wake_lock_init(&pn544_dev->pn544_wake_lock, WAKE_LOCK_SUSPEND, "pn544");
#endif
	pn544_dev->pn544_device.minor = MISC_DYNAMIC_MINOR;
	pn544_dev->pn544_device.name = "pn544";
	pn544_dev->pn544_device.fops = &pn544_dev_fops;

	ret = misc_register(&pn544_dev->pn544_device);
	if (ret) {
		pr_err("%s : misc_register failed\n", __FILE__);
		goto err_misc_register;
	}

	/* request irq.  the irq is set whenever the chip has data available
	 * for reading.  it is cleared when all data has been read.
	 */
	pr_info("%s : requesting IRQ %d\n", __func__, client->irq);
	pn544_dev->irq_enabled = true;
	ret = request_irq(client->irq, pn544_dev_irq_handler,
			  IRQF_TRIGGER_HIGH, client->name, pn544_dev);
	if (ret) {
		dev_err(&client->dev, "request_irq failed\n");
		goto err_request_irq_failed;
	}
	pn544_disable_irq(pn544_dev);
	i2c_set_clientdata(client, pn544_dev);

	return 0;

err_request_irq_failed:
	misc_deregister(&pn544_dev->pn544_device);
err_misc_register:
	mutex_destroy(&pn544_dev->read_mutex);
#if defined(NFC_RF_FIELD_ON_OFF_DETECTED)
	wake_lock_destroy(&pn544_dev->pn544_wake_lock);
#endif
	kfree(pn544_dev);
err_exit:
	gpio_free(platform_data->firm_gpio);
err_firm:
	gpio_free(platform_data->ven_gpio);
err_ven:
	gpio_free(platform_data->irq_gpio);
	return ret;
}
struct link_device *c2c_create_link_device(struct platform_device *pdev)
{
	struct modem_data *modem;
	struct mem_link_device *mld;
	struct link_device *ld;
	int err;
	int i;
	unsigned int irq;
	unsigned long flags;
	char name[MAX_NAME_LEN];
	mif_err("+++\n");

	/**
	 * Get the modem (platform) data
	 */
	modem = (struct modem_data *)pdev->dev.platform_data;
	if (!modem) {
		mif_err("ERR! modem == NULL\n");
		return NULL;
	}

	if (modem->irq_ap_wakeup == 0) {
		mif_err("ERR! no irq_ap_wakeup\n");
		return NULL;
	}

	if (modem->irq_cp_status == 0) {
		mif_err("ERR! no irq_cp_status\n");
		return NULL;
	}

	mif_err("MODEM:%s LINK:%s\n", modem->name, modem->link_name);

	/**
	 * Create a MEMORY link device instance
	 */
	mld = mem_create_link_device(MEM_C2C_SHMEM, modem);
	if (!mld) {
		mif_err("%s: ERR! create_link_device fail\n", modem->link_name);
		return NULL;
	}

	ld = &mld->link_dev;

	/*
	** Link local functions to the corresponding function pointers
	*/
	mld->send_ap2cp_irq = send_int2cp;

	mld->finalize_cp_start = finalize_cp_start;

	mld->forbid_cp_sleep = forbid_cp_sleep;
	mld->permit_cp_sleep = permit_cp_sleep;
	mld->link_active = link_active;

	/*
	** Retrieve SHMEM resource
	*/
	mld->start = c2c_get_phys_base() + c2c_get_sh_rgn_offset();
	mld->size = c2c_get_sh_rgn_size();
	mld->base = mem_register_ipc_rgn(mld, mld->start, mld->size);
	if (!mld->base) {
		mif_err("%s: ERR! register_ipc_rgn fail\n", ld->name);
		goto error;
	}

	/*
	** Initialize SHMEM maps (physical map -> logical map)
	*/
	err = mem_setup_ipc_map(mld);
	if (err < 0) {
		mif_err("%s: ERR! init_ipc_map fail (err %d)\n", ld->name, err);
		goto error;
	}

	/*
	** Register interrupt handlers
	*/
	err = c2c_register_handler(c2c_irq_handler, mld);
	if (err) {
		mif_err("%s: ERR! c2c_register_handler fail (err %d)\n",
			ld->name, err);
		goto error;
	}

	/*
	** Retrieve GPIO#, IRQ#, and IRQ flags for PM
	*/
	mld->gpio_ap_wakeup = modem->gpio_ap_wakeup;
	mld->irq_ap_wakeup = modem->irq_ap_wakeup;

	mld->gpio_cp_wakeup = modem->gpio_cp_wakeup;

	mld->gpio_cp_status = modem->gpio_cp_status;
	mld->irq_cp_status = modem->irq_cp_status;

	mld->gpio_ap_status = modem->gpio_ap_status;

	snprintf(name, MAX_NAME_LEN, "%s_ap_wakeup", ld->name);
	irq = mld->irq_ap_wakeup;
	flags = (IRQF_NO_THREAD | IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH);
	err = mif_register_isr(irq, ap_wakeup_handler, flags, name, mld);
	if (err)
		goto error;

	snprintf(name, MAX_NAME_LEN, "%s_cp_status", ld->name);
	irq = mld->irq_cp_status;
	flags = (IRQF_NO_THREAD | IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH);
	err = mif_register_isr(irq, cp_status_handler, flags, name, mld);
	if (err)
		goto error;

	mif_err("CP2AP_WAKEUP GPIO# = %d\n", mld->gpio_ap_wakeup);
	mif_err("CP2AP_WAKEUP IRQ# = %d\n", mld->irq_ap_wakeup);

	mif_err("AP2CP_WAKEUP GPIO# = %d\n", mld->gpio_cp_wakeup);

	mif_err("CP2AP_STATUS GPIO# = %d\n", mld->gpio_cp_status);
	mif_err("CP2AP_STATUS IRQ# = %d\n", mld->irq_cp_status);

	mif_err("AP2CP_STATUS GPIO# = %d\n", mld->gpio_ap_status);

	/*
	** Initialize locks, completions, bottom halves, etc. for PM
	*/
	sprintf(name, "%s_ap_wlock", ld->name);
	wake_lock_init(&mld->ap_wlock, WAKE_LOCK_SUSPEND, name);

	sprintf(name, "%s_cp_wlock", ld->name);
	wake_lock_init(&mld->cp_wlock, WAKE_LOCK_SUSPEND, name);

	INIT_DELAYED_WORK(&mld->cp_sleep_dwork, release_cp_wakeup);

	spin_lock_init(&mld->pm_lock);
	atomic_set(&mld->ref_cnt, 0);

	gpio_set_value(mld->gpio_ap_status, 0);

	c2c_assign_gpio_ap_wakeup(mld->gpio_ap_wakeup);
	c2c_assign_gpio_ap_status(mld->gpio_ap_status);
	c2c_assign_gpio_cp_wakeup(mld->gpio_cp_wakeup);
	c2c_assign_gpio_cp_status(mld->gpio_cp_status);

	mif_err("---\n");
	return ld;

error:
	kfree(mld);
	mif_err("xxx\n");
	return NULL;
}
static int broadcast_Isdb_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int rc = 0;
	int addr = 0;

#if defined (CONFIG_ARCH_MSM8992) || defined (CONFIG_ARCH_MSM8994)
    printk("[dtv]broadcast_Isdb_i2c_probe client:0x%lX\n", (UDynamic_32_64)client);
#else
    printk("[dtv]broadcast_Isdb_i2c_probe client:0x%X\n", (UDynamic_32_64)client);
#endif

	if(!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		print_log(NULL, "need I2C_FUNC_I2C\n");
		return -ENODEV;
	}
    IsdbCtrlInfo.pdev = to_platform_device(&client->dev);

	/* taew00k.kang added for Device Tree Structure 2013-06-04 [start] */
	addr = client->addr; //Slave Addr
	pr_err("[dtv] i2c Slaveaddr [%x] \n", addr);

	IsdbCtrlInfo.pclient = client;
	//i2c_set_clientdata(client, (void*)&IsdbCtrlInfo.pclient);

#ifdef FEATURE_DMB_USE_XO
    IsdbCtrlInfo.xo_clk = clk_get(&IsdbCtrlInfo.pclient->dev, "isdbt_xo");
    if(IS_ERR(IsdbCtrlInfo.xo_clk)){
        rc = PTR_ERR(IsdbCtrlInfo.xo_clk);
        dev_err(&IsdbCtrlInfo.pclient->dev, "[dtv]could not get clock\n");
        return rc;
    }
    /* We enable/disable the clock only to assure it works */
    rc = clk_prepare_enable(IsdbCtrlInfo.xo_clk);
    if(rc) {
        dev_err(&IsdbCtrlInfo.pclient->dev, "[dtv] could not enable clock\n");
        return rc;
    }
    clk_disable_unprepare(IsdbCtrlInfo.xo_clk);
#endif

#ifdef FEATURE_DMB_USE_PINCTRL
    isdbt_pinctrl_init();
#endif

    /* Config GPIOs */
    broadcast_Isdb_config_gpios();

#ifdef FEATURE_DMB_USE_REGULATOR
    broadcast_isdbt_set_regulator(1);
    broadcast_isdbt_set_regulator(0);
#endif

#ifndef _NOT_USE_WAKE_LOCK_
	wake_lock_init(&IsdbCtrlInfo.wake_lock, WAKE_LOCK_SUSPEND,
					dev_name(&client->dev));
#endif

#if defined (CONFIG_ARCH_MSM8992) || defined (CONFIG_ARCH_MSM8994)
    fc8300_power_on();
    tunerbb_drv_fc8300_read_chip_id();
    fc8300_power_off();
#endif

	return rc;
}
static int bq51221_charger_probe(
						struct i2c_client *client,
						const struct i2c_device_id *id)
{
	struct device_node *of_node = client->dev.of_node;
	struct bq51221_charger_data *charger;
	bq51221_charger_platform_data_t *pdata = client->dev.platform_data;
	int ret = 0;

	dev_info(&client->dev,
		"%s: bq51221 Charger Driver Loading\n", __func__);

	if (of_node) {
		pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
		if (!pdata) {
			dev_err(&client->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}
		ret = bq51221_chg_parse_dt(&client->dev, pdata);
		if (ret < 0)
			goto err_parse_dt;
	} else {
		pdata = client->dev.platform_data;
	}

	charger = kzalloc(sizeof(*charger), GFP_KERNEL);
	if (charger == NULL) {
		dev_err(&client->dev, "Memory is not enough.\n");
		ret = -ENOMEM;
		goto err_wpc_nomem;
	}
	charger->dev = &client->dev;

	ret = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
		I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_I2C_BLOCK);
	if (!ret) {
		ret = i2c_get_functionality(client->adapter);
		dev_err(charger->dev, "I2C functionality is not supported.\n");
		ret = -ENOSYS;
		goto err_i2cfunc_not_support;
	}

	charger->client = client;
	charger->pdata = pdata;

    pr_info("%s: %s\n", __func__, charger->pdata->wireless_charger_name );

	/* if board-init had already assigned irq_base (>=0) ,
	no need to allocate it;
	assign -1 to let this driver allocate resource by itself*/
#if 0 /* this part is for bq51221s */
    if (pdata->irq_base < 0)
        pdata->irq_base = irq_alloc_descs(-1, 0, BQ51221_EVENT_IRQ, 0);
	if (pdata->irq_base < 0) {
		pr_err("%s: irq_alloc_descs Fail! ret(%d)\n",
				__func__, pdata->irq_base);
		ret = -EINVAL;
		goto irq_base_err;
	} else {
		charger->irq_base = pdata->irq_base;
		pr_info("%s: irq_base = %d\n",
			 __func__, charger->irq_base);

#if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,4,0))
		irq_domain_add_legacy(of_node, BQ51221_EVENT_IRQ, charger->irq_base, 0,
				      &irq_domain_simple_ops, NULL);
#endif /*(LINUX_VERSION_CODE>=KERNEL_VERSION(3,4,0))*/
	}
#endif
	i2c_set_clientdata(client, charger);

	charger->psy_chg.name		= pdata->wireless_charger_name;
	charger->psy_chg.type		= POWER_SUPPLY_TYPE_UNKNOWN;
	charger->psy_chg.get_property	= bq51221_chg_get_property;
	charger->psy_chg.set_property	= bq51221_chg_set_property;
	charger->psy_chg.properties	= sec_charger_props;
	charger->psy_chg.num_properties	= ARRAY_SIZE(sec_charger_props);

	mutex_init(&charger->io_lock);

#if 0 /* this part is for bq51221s */

	if (charger->chg_irq) {
		INIT_DELAYED_WORK(
			&charger->isr_work, bq51221_chg_isr_work);

		ret = request_threaded_irq(charger->chg_irq,
				NULL, bq51221_chg_irq_thread,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				"charger-irq", charger);
		if (ret) {
			dev_err(&client->dev,
				"%s: Failed to Reqeust IRQ\n", __func__);
			goto err_supply_unreg;
		}

		ret = enable_irq_wake(charger->chg_irq);
		if (ret < 0)
			dev_err(&client->dev,
				"%s: Failed to Enable Wakeup Source(%d)\n",
				__func__, ret);
	}
#endif
	charger->pdata->cs100_status = 0;
	charger->pdata->pad_mode = BQ51221_PAD_MODE_NONE;
	charger->pdata->siop_level = 100;
	charger->pdata->default_voreg = false;

	ret = power_supply_register(&client->dev, &charger->psy_chg);
	if (ret) {
		dev_err(&client->dev,
			"%s: Failed to Register psy_chg\n", __func__);
		goto err_supply_unreg;
	}

	charger->wqueue = create_workqueue("bq51221_workqueue");
	if (!charger->wqueue) {
		pr_err("%s: Fail to Create Workqueue\n", __func__);
		goto err_pdata_free;
	}

	wake_lock_init(&(charger->wpc_wake_lock), WAKE_LOCK_SUSPEND,
			"wpc_wakelock");
	INIT_DELAYED_WORK(&charger->wpc_work, bq51221_detect_work);

	dev_info(&client->dev,
		"%s: bq51221 Charger Driver Loaded\n", __func__);

	return 0;

err_pdata_free:
	power_supply_unregister(&charger->psy_chg);
err_supply_unreg:
	mutex_destroy(&charger->io_lock);
err_i2cfunc_not_support:
	kfree(charger);
err_wpc_nomem:
err_parse_dt:
	kfree(pdata);
	return ret;
}
Example #9
0
static inline void init_suspend(void)
{
	wake_lock_init(&s5k3h1gx_wake_lock, WAKE_LOCK_IDLE, "s5k3h1gx");
}
static __devinit int tspdrv_tsp5000_probe(struct platform_device *pdev)
{
	int ret = 0, i;   /* initialized below */

	DbgOut((KERN_INFO "tspdrv: tspdrv_tsp5000_probe.\n"));
       atomic_set(&g_nDebugLevel, DBL_ERROR);

        if(!pdev->dev.of_node){
            DbgOut(KERN_ERR "tspdrv_tsp5000: tspdrv_tsp5000 probe failed, DT is NULL");
            return -ENODEV;
        }

        ret = tspdrv_tsp5000_parse_dt(pdev);
        if(ret)
            return ret;
       vibrator_tsp5000_drvdata.power_onoff = NULL;

#ifdef IMPLEMENT_AS_CHAR_DRIVER
    g_nMajor = register_chrdev(0, MODULE_NAME, &fops);
    if (g_nMajor < 0)
	{
        DbgOut((KERN_ERR "tspdrv: can't get major number.\n"));
        return g_nMajor;
    }
#else
    ret = misc_register(&miscdev);
	if (ret)
	{
        DbgOut((KERN_ERR "tspdrv: misc_register failed.\n"));
		goto fail;
	}
#endif

	DbgRecorderInit(());

	vibetonz_ts2665_clk_on(&pdev->dev);

	ImmVibeSPI_ForceOut_Initialize();
	VibeOSKernelLinuxInitTimer();
        ResetOutputData();

	/* Get and concatenate device name and initialize data buffer */
	g_cchDeviceName = 0;
	for (i = 0; i < NUM_ACTUATORS; i++) {
		char *szName = g_szDeviceName + g_cchDeviceName;
		ImmVibeSPI_Device_GetName(i,
			szName, VIBE_MAX_DEVICE_NAME_LENGTH);

		/* Append version information and get buffer length */
		strlcat(szName, VERSION_STR, sizeof(VERSION_STR));
		g_cchDeviceName += strnlen(szName, sizeof(szName));

	}
	wake_lock_init(&vib_wake_lock, WAKE_LOCK_SUSPEND, "vib_present");

	vibetonz_start();

	return 0;
fail:
	return ret;
}
Example #11
0
static int __init spi_tty_init(void)
{
	int retval;
	struct spi_tty_s *spi_tty;

	SPI_IPC_INFO("%s\n", __func__);

	tx_size = 0L;
	tx_time = 0L;
	tx_count = 0L;
	write_count = 0L;

	spi_tty_gbl = kmalloc(sizeof(*spi_tty), GFP_KERNEL);
	if (spi_tty_gbl == NULL) {
		pr_err("%s: Cannot malloc mem!\n", __func__);
		return -ENOMEM;
	}

	memset(spi_tty_gbl, 0x0, sizeof(*spi_tty));
	spi_tty = spi_tty_gbl;
	SPI_IPC_INFO("spi_tty=%p\n", spi_tty);

	spi_tty->write_buf = spi_tty_buf_alloc();
	if (!spi_tty->write_buf) {
		kfree(spi_tty_gbl);
		pr_err("failed to malloc spi_tty write buf!\n");
		return -ENOMEM;
	}

	spi_tty->throttle = 0;
	spi_tty->open_count = 0;
	spi_tty->tx_null = 0;
	spin_lock_init(&spi_tty->port_lock);
	mutex_init(&spi_tty->work_lock);
	INIT_WORK(&spi_tty->write_work, spi_tty_write_worker);
	wake_lock_init(&spi_tty->wakelock, WAKE_LOCK_SUSPEND, "spi_tty_wakelock");

	init_waitqueue_head(&spi_tty->write_wait);
	spi_tty->write_buf_full = 0;

	spi_tty->work_queue = create_singlethread_workqueue("spi_tty_wq");
	if (spi_tty->work_queue  == NULL) {
		kfree(spi_tty);
		kfree(spi_big_trans.tx_buf);
		pr_err("Failed to create work queue\n");
		return -ESRCH;
	}

	spi_slave_message_init(&spi_big_msg);

	spi_big_trans.tx_buf = kmalloc(SPI_TRANSACTION_LEN*2, GFP_KERNEL);
	if (!spi_big_trans.tx_buf) {
		kfree(spi_tty);
		pr_err("%s: Cannot malloc mem!\n", __func__);
		return -ENOMEM;
	}

	spi_big_trans.rx_buf = spi_big_trans.tx_buf + SPI_TRANSACTION_LEN;
	spi_slave_message_add_tail(&spi_big_trans, &spi_big_msg);

	spi_tty_driver = alloc_tty_driver(SPI_TTY_MINORS);
	if (!spi_tty_driver)
		return -ENOMEM;

	spi_tty_driver->owner = THIS_MODULE;
	spi_tty_driver->driver_name = "spi_modem";
	spi_tty_driver->name = "ttySPI";
	spi_tty_driver->major = SPI_TTY_MAJOR;
	spi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
	spi_tty_driver->subtype = SERIAL_TYPE_NORMAL;
	spi_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
	spi_tty_driver->init_termios = tty_std_termios;
	spi_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
	tty_set_operations(spi_tty_driver, &serial_ops);

	retval = tty_register_driver(spi_tty_driver);
	if (retval) {
		pr_err("failed to register spi_tty tty driver");
		put_tty_driver(spi_tty_driver);
		return retval;
	}

	tty_register_device(spi_tty_driver, 0, NULL);

	// Depends on module_init() call sequence, mdm6600_dev_probe may
	mdm6600_spi_dev.cb_context = spi_tty;
	//mdm6600_spi_dev.callback = spi_tty_handle_data;
	mdm6600_spi_dev.callback = NULL;
	mdm6600_spi_dev.handle_master_mrdy = spi_tty_handle_mrdy;
	spi_tty->spi_slave_dev = &mdm6600_spi_dev;

	return retval;
}
Example #12
0
static int tspdrv_probe(struct platform_device *pdev)
{
	int ret, i;   /* initialized below */

	DbgOut((KERN_INFO "tspdrv: tspdrv_probe.\n"));
	motor_min_strength = g_nlra_gp_clk_n*MOTOR_MIN_STRENGTH/100;
	if(!pdev->dev.of_node){
		DbgOut(KERN_ERR "tspdrv: tspdrv probe failed, DT is NULL");
		return -ENODEV;
	}

	ret = tspdrv_parse_dt(pdev);
	if(ret)
		return ret;

	virt_mmss_gp1_base = ioremap(MSM_MMSS_GP1_BASE,0x28);

	if (!virt_mmss_gp1_base)
		panic("tspdrv : Unable to ioremap MSM_MMSS_GP1 memory!");
#if defined(CONFIG_MOTOR_DRV_MAX77828) || defined(CONFIG_MOTOR_DRV_MAX77804K) || defined(CONFIG_MOTOR_DRV_MAX77843)
	vibrator_drvdata.power_onoff = max778xx_haptic_power_onoff;
#endif
	vibrator_drvdata.pwm_dev = NULL;

#ifdef IMPLEMENT_AS_CHAR_DRIVER
	g_nmajor = register_chrdev(0, MODULE_NAME, &fops);
	if (g_nmajor < 0) {
		DbgOut((KERN_ERR "tspdrv: can't get major number.\n"));
		ret = g_nmajor;
		iounmap(virt_mmss_gp1_base);
		return ret;
	}
#else
	ret = misc_register(&miscdev);
	if (ret) {
		DbgOut((KERN_ERR "tspdrv: misc_register failed.\n"));
		iounmap(virt_mmss_gp1_base);
		return ret;
	}
#endif

	DbgRecorderInit(());

	vibetonz_clk_on(&pdev->dev);

	ImmVibeSPI_ForceOut_Initialize();
	VibeOSKernelLinuxInitTimer();

	/* Get and concatenate device name and initialize data buffer */
	g_cchdevice_name = 0;
	for (i = 0; i < NUM_ACTUATORS; i++) {
		char *szName = g_szdevice_name + g_cchdevice_name;
		ImmVibeSPI_Device_GetName(i,
				szName, VIBE_MAX_DEVICE_NAME_LENGTH);

		/* Append version information and get buffer length */
		strlcat(szName, VERSION_STR, sizeof(VERSION_STR));
		g_cchdevice_name += strnlen(szName, sizeof(szName));

		g_samples_buffer[i].nindex_playing_buffer = -1;/* Not playing */
		g_samples_buffer[i].actuator_samples[0].nbuffer_size = 0;
		g_samples_buffer[i].actuator_samples[1].nbuffer_size = 0;
	}
	wake_lock_init(&vib_wake_lock, WAKE_LOCK_SUSPEND, "vib_present");

	vibetonz_start();


	return 0;
}
Example #13
0
static int ssp_probe(struct spi_device *spi)
{
	int iRet = 0;
	struct ssp_data *data;

	pr_info("\n#####################################################\n");
	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;
	}

	iRet = initialize_platformdata(data, spi->dev.platform_data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - failed initialize pdata\n", __func__);
		iRet = -ENOMEM;
		goto err_init_pdata;
	}

	mutex_init(&data->comm_mutex);
	mutex_init(&data->wakeup_mutex);
	mutex_init(&data->reset_mutex);
	mutex_init(&data->enable_mutex);

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

	INIT_DELAYED_WORK(&data->work_firmware, work_function_firmware_update);

	/* check boot loader binary */
	data->fw_dl_state = check_fwbl(data);
	if (data->fw_dl_state == FW_DL_STATE_NONE) {
		iRet = startup_mcu(data);
		if (iRet == ERROR) {
			data->uResetCnt++;
			toggle_mcu_reset(data);
			msleep(SSP_SW_RESET_TIME);
			iRet = startup_mcu(data);
		}

		if (iRet != SUCCESS) {
			pr_err("[SSP]: %s - startup_mcu failed\n", __func__);
			goto err_read_reg;
		}
	}

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

	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_sensors(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not initialize sensor\n", __func__);
		goto err_init_sensor;
	}

	/* 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);
	}

	ssp_enable(data, true);
	data->bProbeIsDone = true;
	pr_info("[SSP]: %s - probe success!\n", __func__);

	enable_debug_timer(data);

	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;
	}

	iRet = 0;

	if (data->check_lpmode() == true) {
		ssp_charging_motion(data, 1);
		data->bLpModeEnabled = true;
		pr_info("[SSP]: LPM Charging...\n");
	} else {
		data->bLpModeEnabled = false;
		pr_info("[SSP]: Normal Booting OK\n");
	}

	goto exit;

err_init_sensor:
	free_irq(data->iIrq, data);
	gpio_free(data->spi->irq);
err_setup_irq:
	destroy_workqueue(data->debug_wq);
err_create_workqueue:
err_input_register_device:
	wake_lock_destroy(&data->ssp_wake_lock);
err_read_reg:
err_reset_null:
err_setup:
	mutex_destroy(&data->enable_mutex);
	mutex_destroy(&data->reset_mutex);
	mutex_destroy(&data->wakeup_mutex);
	mutex_destroy(&data->comm_mutex);
err_init_pdata:
	kfree(data);
	pr_err("[SSP]: %s - probe failed!\n", __func__);
exit:
	pr_info("#####################################################\n\n");
	return iRet;
}
Example #14
0
static int __init apollo_rfkill_probe(struct platform_device *pdev)
{
    int ret;

    s5p_config_gpio_alive_table(ARRAY_SIZE(bt_gpio_table), bt_gpio_table);

    /* Host Wake IRQ */
    wake_lock_init(&bt_host_wakelock, WAKE_LOCK_SUSPEND, "bt_host_wake");

    bt_rfkill = rfkill_allocate(&pdev->dev, RFKILL_TYPE_BLUETOOTH);
    if (!bt_rfkill)
        goto err_rfkill;

    bt_rfkill->name = "bt_rfkill";
    /* userspace cannot take exclusive control */
    bt_rfkill->user_claim_unsupported = 1;
    bt_rfkill->user_claim = 0;
    bt_rfkill->data = pdev;	/* user data */
    bt_rfkill->toggle_radio = bluetooth_set_power;
    /* set bt_rfkill default state to off */
    rfkill_set_default(RFKILL_TYPE_BLUETOOTH, RFKILL_STATE_SOFT_BLOCKED);

    ret = rfkill_register(bt_rfkill);
    if (ret) {
        rfkill_free(bt_rfkill);
        goto err_rfkill;
    }

#ifdef BT_SLEEP_ENABLE
    wake_lock_init(&bt_wakelock, WAKE_LOCK_SUSPEND, "bt_wake");

    bt_sleep = rfkill_allocate(&pdev->dev, RFKILL_TYPE_BLUETOOTH);
    if (!bt_sleep)
        goto err_sleep;

    bt_sleep->name = "bt_sleep";
    /* userspace cannot take exclusive control */
    bt_sleep->user_claim_unsupported = 1;
    bt_sleep->user_claim = 0;
    bt_sleep->data = NULL;	/* user data */
    bt_sleep->toggle_radio = bluetooth_set_sleep;

    ret = rfkill_register(bt_sleep);
    if (ret) {
        rfkill_free(bt_sleep);
        goto err_sleep;
    }

    /* set bt_sleep default state to wake_unlock */
    rfkill_force_state(bt_sleep, RFKILL_STATE_UNBLOCKED);
#endif /* BT_SLEEP_ENABLE */

    return 0;

err_sleep:
    wake_lock_destroy(&bt_wakelock);
    rfkill_unregister(bt_rfkill);

err_rfkill:
    wake_lock_destroy(&bt_host_wakelock);
    return ret;

}
static int __init snddev_icodec_init(void)
{
	s32 rc;
	struct snddev_icodec_drv_state *icodec_drv = &snddev_icodec_drv;

	rc = platform_driver_register(&snddev_icodec_driver);
	if (IS_ERR_VALUE(rc))
		goto error_platform_driver;
	icodec_drv->rx_mclk = clk_get(NULL, "mi2s_codec_rx_m_clk");
	if (IS_ERR(icodec_drv->rx_mclk))
		goto error_rx_mclk;
	icodec_drv->rx_sclk = clk_get(NULL, "mi2s_codec_rx_s_clk");
	if (IS_ERR(icodec_drv->rx_sclk))
		goto error_rx_sclk;
	icodec_drv->tx_mclk = clk_get(NULL, "mi2s_codec_tx_m_clk");
	if (IS_ERR(icodec_drv->tx_mclk))
		goto error_tx_mclk;
	icodec_drv->tx_sclk = clk_get(NULL, "mi2s_codec_tx_s_clk");
	if (IS_ERR(icodec_drv->tx_sclk))
		goto error_tx_sclk;
	icodec_drv->lpa_codec_clk = clk_get(NULL, "lpa_codec_clk");
	if (IS_ERR(icodec_drv->lpa_codec_clk))
		goto error_lpa_codec_clk;
	icodec_drv->lpa_core_clk = clk_get(NULL, "lpa_core_clk");
	if (IS_ERR(icodec_drv->lpa_core_clk))
		goto error_lpa_core_clk;
	icodec_drv->lpa_p_clk = clk_get(NULL, "lpa_pclk");
	if (IS_ERR(icodec_drv->lpa_p_clk))
		goto error_lpa_p_clk;

#ifdef CONFIG_DEBUG_FS
	debugfs_sdev_dent = debugfs_create_dir("snddev_icodec", 0);
	if (debugfs_sdev_dent) {
		debugfs_afelb = debugfs_create_file("afe_loopback",
		S_IFREG | S_IWUGO, debugfs_sdev_dent,
		(void *) "afe_loopback", &snddev_icodec_debug_fops);
		debugfs_adielb = debugfs_create_file("adie_loopback",
		S_IFREG | S_IWUGO, debugfs_sdev_dent,
		(void *) "adie_loopback", &snddev_icodec_debug_fops);
	}
#endif
	mutex_init(&icodec_drv->rx_lock);
	mutex_init(&icodec_drv->tx_lock);
	icodec_drv->rx_active = 0;
	icodec_drv->tx_active = 0;
	icodec_drv->lpa = NULL;
	wake_lock_init(&icodec_drv->tx_idlelock, WAKE_LOCK_IDLE,
			"snddev_tx_idle");
	wake_lock_init(&icodec_drv->rx_idlelock, WAKE_LOCK_IDLE,
			"snddev_rx_idle");
	return 0;

error_lpa_p_clk:
	clk_put(icodec_drv->lpa_core_clk);
error_lpa_core_clk:
	clk_put(icodec_drv->lpa_codec_clk);
error_lpa_codec_clk:
	clk_put(icodec_drv->tx_sclk);
error_tx_sclk:
	clk_put(icodec_drv->tx_mclk);
error_tx_mclk:
	clk_put(icodec_drv->rx_sclk);
error_rx_sclk:
	clk_put(icodec_drv->rx_mclk);
error_rx_mclk:
	platform_driver_unregister(&snddev_icodec_driver);
error_platform_driver:

	MM_ERR("encounter error\n");
	return -ENODEV;
}
static int htc_headset_pmic_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct htc_headset_pmic_platform_data *pdata = pdev->dev.platform_data;
#ifdef HTC_HEADSET_CONFIG_MSM_RPC
	uint32_t vers = 0;
#endif

	HS_LOG("++++++++++++++++++++");

	hi = kzalloc(sizeof(struct htc_35mm_pmic_info), GFP_KERNEL);
	if (!hi)
		return -ENOMEM;

	hi->pdata.driver_flag = pdata->driver_flag;
	hi->pdata.hpin_gpio = pdata->hpin_gpio;
	hi->pdata.hpin_irq = pdata->hpin_irq;
	hi->pdata.key_gpio = pdata->key_gpio;
	hi->pdata.key_irq = pdata->key_irq;
	hi->pdata.key_enable_gpio = pdata->key_enable_gpio;
	hi->pdata.adc_mpp = pdata->adc_mpp;
	hi->pdata.adc_amux = pdata->adc_amux;
	hi->pdata.hs_controller = pdata->hs_controller;
	hi->pdata.hs_switch = pdata->hs_switch;
	hi->pdata.adc_mic = pdata->adc_mic;
	hi->htc_accessory_class = hs_get_attribute_class();
	register_attributes();

	if (!hi->pdata.adc_mic)
		hi->pdata.adc_mic = HS_DEF_MIC_ADC_16_BIT_MIN;

	if (pdata->adc_mic_bias[0] && pdata->adc_mic_bias[1]) {
		memcpy(hi->pdata.adc_mic_bias, pdata->adc_mic_bias,
		       sizeof(hi->pdata.adc_mic_bias));
		hi->pdata.adc_mic = hi->pdata.adc_mic_bias[0];
	} else {
		hi->pdata.adc_mic_bias[0] = hi->pdata.adc_mic;
		hi->pdata.adc_mic_bias[1] = HS_DEF_MIC_ADC_16_BIT_MAX;
	}

	if (pdata->adc_remote[5])
		memcpy(hi->pdata.adc_remote, pdata->adc_remote,
		       sizeof(hi->pdata.adc_remote));

	if (pdata->adc_metrico[0] && pdata->adc_metrico[1])
		memcpy(hi->pdata.adc_metrico, pdata->adc_metrico,
		       sizeof(hi->pdata.adc_metrico));

	hi->hpin_irq_type = IRQF_TRIGGER_NONE;
	hi->hpin_debounce = HS_JIFFIES_ZERO;
	hi->key_irq_type = IRQF_TRIGGER_NONE;

	wake_lock_init(&hi->hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME);

	detect_wq = create_workqueue("HS_PMIC_DETECT");
	if (detect_wq  == NULL) {
		ret = -ENOMEM;
		HS_ERR("Failed to create detect workqueue");
		goto err_create_detect_work_queue;
	}

	button_wq = create_workqueue("HS_PMIC_BUTTON");
	if (button_wq == NULL) {
		ret = -ENOMEM;
		HS_ERR("Failed to create button workqueue");
		goto err_create_button_work_queue;
	}

	if (hi->pdata.hpin_gpio) {
		ret = hs_pmic_request_irq(hi->pdata.hpin_gpio,
				&hi->pdata.hpin_irq, detect_irq_handler,
				hi->hpin_irq_type, "HS_PMIC_DETECT", 1);
		if (ret < 0) {
			HS_ERR("Failed to request PMIC HPIN IRQ (0x%X)", ret);
			goto err_request_detect_irq;
		}
		disable_irq(hi->pdata.hpin_irq);
	}

	if (hi->pdata.key_gpio) {
		ret = hs_pmic_request_irq(hi->pdata.key_gpio,
				&hi->pdata.key_irq, button_irq_handler,
				hi->key_irq_type, "HS_PMIC_BUTTON", 1);
		if (ret < 0) {
			HS_ERR("Failed to request PMIC button IRQ (0x%X)", ret);
			goto err_request_button_irq;
		}
		disable_irq(hi->pdata.key_irq);
	}

#ifdef HTC_HEADSET_CONFIG_MSM_RPC
	if (hi->pdata.driver_flag & DRIVER_HS_PMIC_RPC_KEY) {
		/* Register ADC RPC client */
		endpoint_adc = msm_rpc_connect(HS_RPC_CLIENT_PROG,
					       HS_RPC_CLIENT_VERS, 0);
		if (IS_ERR(endpoint_adc)) {
			hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_RPC_KEY;
			HS_LOG("Failed to register ADC RPC client");
		} else
			HS_LOG("Register ADC RPC client successfully");
	}

	if (hi->pdata.driver_flag & DRIVER_HS_PMIC_DYNAMIC_THRESHOLD) {
		/* Register threshold RPC client */
		vers = HS_PMIC_RPC_CLIENT_VERS_3_1;
		endpoint_current = msm_rpc_connect_compatible(
				   HS_PMIC_RPC_CLIENT_PROG, vers, 0);
		if (!endpoint_current) {
			vers = HS_PMIC_RPC_CLIENT_VERS_2_1;
			endpoint_current = msm_rpc_connect(
					   HS_PMIC_RPC_CLIENT_PROG, vers, 0);
		}
		if (!endpoint_current) {
			vers = HS_PMIC_RPC_CLIENT_VERS_1_1;
			endpoint_current = msm_rpc_connect(
					   HS_PMIC_RPC_CLIENT_PROG, vers, 0);
		}
		if (!endpoint_current) {
			vers = HS_PMIC_RPC_CLIENT_VERS;
			endpoint_current = msm_rpc_connect(
					   HS_PMIC_RPC_CLIENT_PROG, vers, 0);
		}
		if (IS_ERR(endpoint_current)) {
			hi->pdata.driver_flag &=
				~DRIVER_HS_PMIC_DYNAMIC_THRESHOLD;
			HS_LOG("Failed to register threshold RPC client");
		} else
			HS_LOG("Register threshold RPC client successfully"
			       " (0x%X)", vers);
	}
#else
	hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_RPC_KEY;
	hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_DYNAMIC_THRESHOLD;
#endif

	queue_delayed_work(detect_wq, &irq_init_work, HS_JIFFIES_IRQ_INIT);

	hs_pmic_register();
	hs_notify_driver_ready(DRIVER_NAME);

	HS_LOG("--------------------");

	return 0;

err_request_button_irq:
	if (hi->pdata.hpin_gpio) {
		free_irq(hi->pdata.hpin_irq, 0);
		gpio_free(hi->pdata.hpin_gpio);
	}

err_request_detect_irq:
	destroy_workqueue(button_wq);

err_create_button_work_queue:
	destroy_workqueue(detect_wq);

err_create_detect_work_queue:
	wake_lock_destroy(&hi->hs_wake_lock);
	kfree(hi);

	HS_ERR("Failed to register %s driver", DRIVER_NAME);

	return ret;
}
Example #17
0
static int vpu_probe(struct platform_device *pdev)
{
	int ret;
	struct resource			*regs;
	struct jz_vpu *vpu;

	vpu = kzalloc(sizeof(struct jz_vpu), GFP_KERNEL);
	if (!vpu)
		ret = -ENOMEM;

	vpu->irq = platform_get_irq(pdev, 0);
	if(vpu->irq < 0) {
		dev_err(&pdev->dev, "get irq failed\n");
		ret = vpu->irq;
		goto err_get_mem;
	}

	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!regs) {
		dev_err(&pdev->dev, "No iomem resource\n");
		ret = -ENXIO;
		goto err_get_mem;
	}

	vpu->iomem = ioremap(regs->start, resource_size(regs));
	if (!vpu->iomem) {
		dev_err(&pdev->dev, "ioremap failed\n");
		ret = -ENXIO;
		goto err_get_mem;
	}

	vpu->clk_gate = clk_get(&pdev->dev, "vpu");
	if (IS_ERR(vpu->clk_gate)) {
		ret = PTR_ERR(vpu->clk_gate);
		goto err_get_clk_gate;
	}

	vpu->dev = &pdev->dev;
	vpu->mdev.minor = MISC_DYNAMIC_MINOR;
	vpu->mdev.name =  "jz-vpu";
	vpu->mdev.fops = &vpu_misc_fops;

	spin_lock_init(&vpu->lock);

	ret = misc_register(&vpu->mdev);
	if (ret < 0) {
		dev_err(&pdev->dev, "misc_register failed\n");
		goto err_registe_misc;
	}
	platform_set_drvdata(pdev, vpu);

	wake_lock_init(&vpu->wake_lock, WAKE_LOCK_SUSPEND, "vpu");

	mutex_init(&vpu->mutex);

	init_completion(&vpu->done);
	ret = request_irq(vpu->irq, vpu_interrupt, IRQF_DISABLED,
			  "vpu",vpu);
	if (ret < 0) {
		dev_err(&pdev->dev, "request_irq failed\n");
		goto err_request_irq;
	}

	disable_irq_nosync(vpu->irq);

	return 0;

err_request_irq:
	misc_deregister(&vpu->mdev);
err_registe_misc:
	clk_put(vpu->clk_gate);
err_get_clk_gate:
	iounmap(vpu->iomem);
err_get_mem:
	kfree(vpu);
	return ret;
}
Example #18
0
int ssp_sensorhub_initialize(struct ssp_data *ssp_data)
{
	struct ssp_sensorhub_data *hub_data;
	int ret;

	/* allocate memory for sensorhub data */
	hub_data = kzalloc(sizeof(*hub_data), GFP_KERNEL);
	if (!hub_data) {
		sensorhub_err("allocate memory for sensorhub data err");
		ret = -ENOMEM;
		goto exit;
	}
	hub_data->ssp_data = ssp_data;
	ssp_data->hub_data = hub_data;

	/* init wakelock, list, waitqueue, completion and spinlock */
	wake_lock_init(&hub_data->sensorhub_wake_lock, WAKE_LOCK_SUSPEND,
			"ssp_sensorhub_wake_lock");
	init_waitqueue_head(&hub_data->sensorhub_wq);
	init_completion(&hub_data->read_done);
	init_completion(&hub_data->big_read_done);
	init_completion(&hub_data->big_write_done);
	spin_lock_init(&hub_data->sensorhub_lock);
	mutex_init(&hub_data->big_events_lock);

	/* allocate sensorhub input device */
	hub_data->sensorhub_input_dev = input_allocate_device();
	if (!hub_data->sensorhub_input_dev) {
		sensorhub_err("allocate sensorhub input device err");
		ret = -ENOMEM;
		goto err_input_allocate_device_sensorhub;
	}

	/* set sensorhub input device */
	input_set_drvdata(hub_data->sensorhub_input_dev, hub_data);
	hub_data->sensorhub_input_dev->name = "ssp_context";
	input_set_capability(hub_data->sensorhub_input_dev, EV_REL, DATA);
	input_set_capability(hub_data->sensorhub_input_dev, EV_REL, BIG_DATA);
	input_set_capability(hub_data->sensorhub_input_dev, EV_REL, NOTICE);

	/* register sensorhub input device */
	ret = input_register_device(hub_data->sensorhub_input_dev);
	if (ret < 0) {
		sensorhub_err("register sensorhub input device err(%d)", ret);
		input_free_device(hub_data->sensorhub_input_dev);
		goto err_input_register_device_sensorhub;
	}

	/* register sensorhub misc device */
	hub_data->sensorhub_device.minor = MISC_DYNAMIC_MINOR;
	hub_data->sensorhub_device.name = "ssp_sensorhub";
	hub_data->sensorhub_device.fops = &ssp_sensorhub_fops;

	ret = misc_register(&hub_data->sensorhub_device);
	if (ret < 0) {
		sensorhub_err("register sensorhub misc device err(%d)", ret);
		goto err_misc_register;
	}

	/* allocate fifo */
	ret = kfifo_alloc(&hub_data->fifo,
		sizeof(void *) * LIST_SIZE, GFP_KERNEL);
	if (ret) {
		sensorhub_err("kfifo allocate err(%d)", ret);
		goto err_kfifo_alloc;
	}

	/* create and run sensorhub thread */
	hub_data->sensorhub_task = kthread_run(ssp_sensorhub_thread,
				(void *)hub_data, "ssp_sensorhub_thread");
	if (IS_ERR(hub_data->sensorhub_task)) {
		ret = PTR_ERR(hub_data->sensorhub_task);
		goto err_kthread_run;
	}

	return 0;

err_kthread_run:
	kfifo_free(&hub_data->fifo);
err_kfifo_alloc:
	misc_deregister(&hub_data->sensorhub_device);
err_misc_register:
	input_unregister_device(hub_data->sensorhub_input_dev);
err_input_register_device_sensorhub:
err_input_allocate_device_sensorhub:
	complete_all(&hub_data->big_write_done);
	complete_all(&hub_data->big_read_done);
	complete_all(&hub_data->read_done);
	wake_lock_destroy(&hub_data->sensorhub_wake_lock);
	kfree(hub_data);
exit:
	return ret;
}
static int __devinit bcm4329_rfkill_probe(struct platform_device *pdev)
{
	int rc = 0;
	bool default_state = true;
	
	DBG("Enter::%s,line=%d\n",__FUNCTION__,__LINE__);
	
	/* default to bluetooth off */
 	bcm4329_set_block(NULL, default_state); /* blocked -> bt off */
	 
	gBtCtrl.bt_rfk = rfkill_alloc(bt_name, 
                NULL, 
                RFKILL_TYPE_BLUETOOTH, 
                &bcm4329_rfk_ops, 
                NULL);

	if (!gBtCtrl.bt_rfk)
	{
		printk("fail to rfkill_allocate************\n");
		return -ENOMEM;
	}
	
	rfkill_set_states(gBtCtrl.bt_rfk, default_state, false);

	rc = rfkill_register(gBtCtrl.bt_rfk);
	if (rc)
	{
		printk("failed to rfkill_register,rc=0x%x\n",rc);
		rfkill_destroy(gBtCtrl.bt_rfk);
	}
	
	gpio_request(BT_GPIO_POWER, NULL);
	gpio_request(BT_GPIO_RESET, NULL);
	gpio_request(BT_GPIO_WAKE_UP, NULL);

#if BT_WAKE_HOST_SUPPORT
    init_timer(&(gBtCtrl.tl));
    gBtCtrl.tl.expires = jiffies + BT_WAKE_LOCK_TIMEOUT*HZ;        
    gBtCtrl.tl.function = timer_hostSleep;        
    add_timer(&(gBtCtrl.tl));
    gBtCtrl.b_HostWake = false;
    
	wake_lock_init(&(gBtCtrl.bt_wakelock), WAKE_LOCK_SUSPEND, "bt_wake");
	
	rc = gpio_request(BT_GPIO_WAKE_UP_HOST, "bt_wake");
	if (rc) {
		printk("%s:failed to request RAHO_BT_WAKE_UP_HOST\n",__FUNCTION__);
	}
	
	IOMUX_BT_GPIO_WAKE_UP_HOST();
	gpio_pull_updown(BT_GPIO_WAKE_UP_HOST,GPIOPullUp);
	rc = request_irq(gpio_to_irq(BT_GPIO_WAKE_UP_HOST),bcm4329_wake_host_irq,IRQF_TRIGGER_FALLING,NULL,NULL);
	if(rc)
	{
		printk("%s:failed to request RAHO_BT_WAKE_UP_HOST irq\n",__FUNCTION__);
		gpio_free(BT_GPIO_WAKE_UP_HOST);
	}
	enable_irq_wake(gpio_to_irq(BT_GPIO_WAKE_UP_HOST)); // so RAHO_BT_WAKE_UP_HOST can wake up system

	printk(KERN_INFO "bcm4329 module has been initialized,rc=0x%x\n",rc);
 #endif
 
	return rc;

	
}
Example #20
0
static int acc_con_probe(struct platform_device *pdev)
{
	struct acc_con_info *acc;
	struct acc_con_platform_data *pdata = pdev->dev.platform_data;
	int	retval;

	ACC_CONDEV_DBG("");

	if (pdata == NULL) {
		pr_err("%s: no pdata\n", __func__);
		return -ENODEV;
	}

	acc = kzalloc(sizeof(*acc), GFP_KERNEL);
	if (!acc)
		return -ENOMEM;

	acc->pdata = pdata;
	acc->current_dock = DOCK_NONE;
	acc->current_accessory = ACCESSORY_NONE;
#ifdef CONFIG_MHL_SII9234
	acc->mhl_irq = gpio_to_irq(pdata->mhl_irq_gpio);
	acc->mhl_pwr_state = false;
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
	acc->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	acc->early_suspend.suspend = acc_con_early_suspend;
	acc->early_suspend.resume = acc_con_late_resume;
	register_early_suspend(&acc->early_suspend);
	mutex_init(&acc->lock);
	INIT_DELAYED_WORK(&acc->acc_con_work, acc_con_late_resume_work);
#endif

	dev_set_drvdata(&pdev->dev, acc);

	acc->acc_dev = &pdev->dev;
#ifdef CONFIG_MHL_SII9234
	wake_lock_init(&acc->mhl_wake_lock, WAKE_LOCK_SUSPEND, "mhl");
	retval = i2c_add_driver(&SII9234A_i2c_driver);
	if (retval) {
		pr_err("[MHL SII9234A] can't add i2c driver\n");
		goto err_i2c_a;
	} else {
		pr_info("[MHL SII9234A] add i2c driver\n");
	}

	retval = i2c_add_driver(&SII9234B_i2c_driver);
	if (retval) {
		pr_err("[MHL SII9234B] can't add i2c driver\n");
		goto err_i2c_b;
	} else {
		pr_info("[MHL SII9234B] add i2c driver\n");
	}

	retval = i2c_add_driver(&SII9234C_i2c_driver);
	if (retval) {
		pr_err("[MHL SII9234C] can't add i2c driver\n");
		goto err_i2c_c;
	} else {
		pr_info("[MHL SII9234C] add i2c driver\n");
	}

	retval = i2c_add_driver(&SII9234_i2c_driver);
	if (retval) {
		pr_err("[MHL SII9234] can't add i2c driver\n");
		goto err_i2c;
	} else {
		pr_info("[MHL SII9234] add i2c driver\n");
	}

#endif

	acc->dock_switch.name = "dock";
	retval = switch_dev_register(&acc->dock_switch);
	if (retval < 0)
		goto err_sw_dock;

	acc->ear_jack_switch.name = "usb_audio";
	retval = switch_dev_register(&acc->ear_jack_switch);
	if (retval < 0)
		goto err_sw_jack;

	wake_lock_init(&acc->wake_lock, WAKE_LOCK_SUSPEND, "30pin_con");

#ifdef CONFIG_SEC_KEYBOARD_DOCK
	INIT_DELAYED_WORK(&acc->dwork, delay_worker);
	schedule_delayed_work(&acc->dwork, msecs_to_jiffies(25000));

	INIT_DELAYED_WORK(&acc->acc_id_dwork, acc_dwork_accessory_detect);
#else
	retval = acc_con_interrupt_init(acc);
	if (retval != 0)
		goto err_irq_dock;

	retval = acc_ID_interrupt_init(acc);
	if (retval != 0)
		goto err_irq_acc;

	INIT_DELAYED_WORK(&acc->acc_id_dwork, acc_dwork_accessory_detect);

	if (acc->pdata->dock_irq_gpio) {
		if (!gpio_get_value(acc->pdata->dock_irq_gpio))
			schedule_delayed_work(&acc->acc_id_dwork,
				msecs_to_jiffies(DETECTION_DELAY_MS));
	}
#endif

	if (device_create_file(acc->acc_dev, &dev_attr_MHD_file) < 0)
		printk("Failed to create device file(%s)!\n", dev_attr_MHD_file.attr.name);

	return 0;

#ifndef CONFIG_SEC_KEYBOARD_DOCK
err_irq_acc:
	free_irq(acc->accessory_irq, acc);
err_irq_dock:
	switch_dev_unregister(&acc->ear_jack_switch);
#endif
err_sw_jack:
	switch_dev_unregister(&acc->dock_switch);
err_sw_dock:
	i2c_del_driver(&SII9234_i2c_driver);
err_i2c:
	i2c_del_driver(&SII9234C_i2c_driver);
err_i2c_c:
	i2c_del_driver(&SII9234B_i2c_driver);
err_i2c_b:
	i2c_del_driver(&SII9234A_i2c_driver);
err_i2c_a:
#ifdef CONFIG_HAS_EARLYSUSPEND
	cancel_delayed_work_sync(&acc->acc_con_work);
#endif
	kfree(acc);

	return retval;
}
Example #21
0
static int gp2a_i2c_probe(struct i2c_client *client,
                          const struct i2c_device_id *id)
{
    struct gp2a_data *gp2a;
    struct gp2ap020_pdata *pdata = client->dev.platform_data;
    u8 value = 0;
    int err = 0;

    pr_info("%s : probe start!\n", __func__);

    if (!pdata) {
        pr_err("%s: missing pdata!\n", __func__);
        err = -EINVAL;
        goto done;
    }
    /*
    	if (!pdata->power_on) {
    		pr_err("%s: incomplete pdata!\n", __func__);
    		err = -EINVAL;
    		goto done;
    	}
    */
    /* allocate driver_data */
    gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
    if (!gp2a) {
        pr_err("kzalloc error\n");
        err = -ENOMEM;
        goto done;
    }

    gp2a->pdata = pdata;
    gp2a->client = client;

    gp2a->proximity_enabled = 0;

    gp2a->light_enabled = 0;
    gp2a->light_delay = SENSOR_DEFAULT_DELAY;

    i2c_set_clientdata(client, gp2a);

    if (pdata->power_on)
        pdata->power_on(true);

    if (pdata->version) { /* GP2AP030 */
        gp2a_reg[1][1] = 0x1A;
        if (pdata->thresh[0])
            gp2a_reg[3][1] = pdata->thresh[0];
        else
            gp2a_reg[3][1] = 0x08;
        if (pdata->thresh[1])
            gp2a_reg[5][1] = pdata->thresh[1];
        else
            gp2a_reg[5][1] = 0x0A;
    }

    INIT_DELAYED_WORK(&gp2a->light_work, gp2a_work_func_light);
    INIT_WORK(&gp2a->proximity_work, gp2a_work_func_prox);

    err = proximity_input_init(gp2a);
    if (err < 0)
        goto error_setup_reg_prox;

    err = light_input_init(gp2a);
    if (err < 0)
        goto error_setup_reg_light;

    err = sysfs_create_group(&gp2a->proximity_input_dev->dev.kobj,
                             &proximity_attribute_group);
    if (err < 0)
        goto err_sysfs_create_group_proximity;

    err = sysfs_create_group(&gp2a->light_input_dev->dev.kobj,
                             &lightsensor_attribute_group);
    if (err)
        goto err_sysfs_create_group_light;

    mutex_init(&gp2a->light_mutex);
    mutex_init(&gp2a->data_mutex);

    /* wake lock init */
    wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND,
                   "prx_wake_lock");

    /* GP2A Regs INIT SETTINGS  and Check I2C communication */
    /* shutdown mode op[3]=0 */
    value = 0x00;
    err = gp2a_i2c_write(gp2a, (u8) (COMMAND1), &value);
    if (err < 0) {
        pr_err("%s failed : threre is no such device.\n", __func__);
        goto err_no_device;
    }

    /* Setup irq */
    err = gp2a_setup_irq(gp2a);
    if (err) {
        pr_err("%s: could not setup irq\n", __func__);
        goto err_setup_irq;
    }

    err = sensors_register(gp2a->light_sensor_device,
                           gp2a, additional_light_attrs, "light_sensor");
    if (err) {
        pr_err("%s: cound not register sensor device\n", __func__);
        goto err_sysfs_create_factory_light;
    }

    err = sensors_register(gp2a->proximity_sensor_device,
                           gp2a, additional_proximity_attrs, "proximity_sensor");
    if (err) {
        pr_err("%s: cound not register sensor device\n", __func__);
        goto err_sysfs_create_factory_proximity;
    }

#ifdef CONFIG_SENSOR_USE_SYMLINK
    err =  sensors_initialize_symlink(gp2a->proximity_input_dev);
    if (err) {
        pr_err("%s: cound not make proximity sensor symlink(%d).\n",
               __func__, err);
        goto err_sensors_initialize_symlink_proximity;
    }

    err =  sensors_initialize_symlink(gp2a->light_input_dev);
    if (err) {
        pr_err("%s: cound not make light sensor symlink(%d).\n",
               __func__, err);
        goto err_sensors_initialize_symlink_light;
    }
#endif

    input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, 1);

    pr_info("%s : probe success!\n", __func__);

    return 0;

#ifdef CONFIG_SENSOR_USE_SYMLINK
err_sensors_initialize_symlink_light:
    sensors_delete_symlink(gp2a->proximity_input_dev);
err_sensors_initialize_symlink_proximity:
#endif
err_sysfs_create_factory_proximity:
err_sysfs_create_factory_light:
    free_irq(gp2a->irq, gp2a);
    gpio_free(gp2a->pdata->p_out);
err_setup_irq:
err_no_device:
    wake_lock_destroy(&gp2a->prx_wake_lock);
    mutex_destroy(&gp2a->light_mutex);
    mutex_destroy(&gp2a->data_mutex);
    sysfs_remove_group(&gp2a->light_input_dev->dev.kobj,
                       &lightsensor_attribute_group);
err_sysfs_create_group_light:
    sysfs_remove_group(&gp2a->proximity_input_dev->dev.kobj,
                       &proximity_attribute_group);
err_sysfs_create_group_proximity:
    input_unregister_device(gp2a->light_input_dev);
error_setup_reg_light:
    input_unregister_device(gp2a->proximity_input_dev);
error_setup_reg_prox:
    if (pdata->power_on)
        pdata->power_on(false);
    kfree(gp2a);
done:
    return err;
}
Example #22
0
static int __devinit modemctl_probe(struct platform_device *pdev)
{
	struct modemctl_platform_data *pdata = pdev->dev.platform_data;
	struct device *dev = &pdev->dev;
	struct modemctl *mc;
	int irq;
	int error;

	if (!pdata) {
		dev_err(dev, "No platform data\n");
		return -EINVAL;
	}

	mc = kzalloc(sizeof(struct modemctl), GFP_KERNEL);
	if (!mc) {
		dev_err(dev, "Failed to allocate device\n");
		return -ENOMEM;
	}

	mc->gpio_phone_on = pdata->gpio_phone_on;
	mc->gpio_phone_active = pdata->gpio_phone_active;
	mc->gpio_pda_active = pdata->gpio_pda_active;
	mc->gpio_cp_dump_int = pdata->gpio_cp_dump_int;
	mc->gpio_ap_cp_int1 = pdata->gpio_ap_cp_int1;
	mc->gpio_ap_cp_int2 = pdata->gpio_ap_cp_int2;

	mc->ops = &pdata->ops;
	mc->dev = dev;
	dev_set_drvdata(mc->dev, mc);

	error = sysfs_create_group(&mc->dev->kobj, &modemctl_group);
	if (error) {
		dev_err(dev, "Failed to create sysfs files\n");
		goto fail;
	}
	mc->group = &modemctl_group;

	INIT_DELAYED_WORK(&mc->work, mc_work);
	INIT_WORK(&mc->cpdump_work, mc_cpdump_worker);
	wake_lock_init(&mc->reset_lock, WAKE_LOCK_SUSPEND, "modemctl");

	irq = gpio_to_irq(pdata->gpio_phone_active);
	error = request_irq(irq, modemctl_irq_handler,
			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
			"phone_active", mc);
	if (error) {
		dev_err(dev, "(%d) Failed to allocate an interrupt(%d)\n",
			__LINE__, irq);
		goto fail;
	}
	mc->irq[0] = irq;
	enable_irq_wake(irq);

	irq = gpio_to_irq(pdata->gpio_cp_dump_int);
#if defined(CONFIG_CHN_CMCC_SPI_SPRD)
	error = request_irq(irq, modemctl_irq_handler,
			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
			"CP_DUMP_INT", mc);
#else
	error = request_irq(irq, modemctl_cpdump_irq,
			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
			"CP_DUMP_INT", mc);
#endif
	if (error) {
		dev_err(dev, "(%d) Failed to allocate an interrupt(%d)\n",
			__LINE__, irq);
		goto fail;
	}
	mc->irq[1] = irq;
	enable_irq_wake(irq);
	mc->debug_cnt = 0;

	device_init_wakeup(&pdev->dev, pdata->wakeup);
	platform_set_drvdata(pdev, mc);
	global_mc = mc;

	pr_info("[%s] Done\n ", __func__);
	return 0;

fail:
	_free_all(mc);
	return error;
}
static int __init strasbourg_ps_init(void)
{
	int irq;	
	int ret = 0;	

	strasbourg_ps_pdev = platform_device_register_simple("strasbourg-power-supply", 0, NULL, 0);
	if (IS_ERR(strasbourg_ps_pdev)) {
		return PTR_ERR(strasbourg_ps_pdev);
	}
	ret = power_supply_register(&strasbourg_ps_pdev->dev, &strasbourg_ps_bat);
	if (ret) {
		goto bat_failed;
	}
	ret = power_supply_register(&strasbourg_ps_pdev->dev, &strasbourg_ps_ac);
	if (ret) {
		goto ac_failed;
	}
	ret = power_supply_register(&strasbourg_ps_pdev->dev, &strasbourg_ps_usb);
	if (ret) {
		goto usb_failed;
	}
	/*
	 * Make sure to update the wakelock name used in suspend_late (wakelock.c) if the wakelock
	 * name "strasbourg-power-supply" is changed.
	 */
	wake_lock_init(&strasbourg_ps_wake_lock, WAKE_LOCK_SUSPEND, "strasbourg-power-supply");

	ret = gpio_request(TT_VGPIO_ON_OFF, "ON_OFF") || gpio_direction_input (TT_VGPIO_ON_OFF);
	if (ret)
		goto gpio_alloc_failed;

	/* Take a wake lock if SYS_ON is high */
	if (gpio_get_value (TT_VGPIO_ON_OFF)) {
		wake_lock (&strasbourg_ps_wake_lock);
	}
	else {
		start_timer();
	}
	irq = gpio_to_irq(TT_VGPIO_ON_OFF);
	ret = request_irq(irq, strasbourg_ps_isr,
			  IRQF_SHARED |IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
			  "strasbourg-power-supply",
			   strasbourg_ps_pdev);
	if (ret) {
		goto request_irq_failed;
	}

	enable_irq_wake(irq);
	poweroff_work_queue = create_singlethread_workqueue("poweroff");
        if (poweroff_work_queue == NULL) {
                ret = -ENOMEM;
                goto poweroff_work_queue_create_failed;
        }

	printk(KERN_INFO "Strasbourg: power supply driver loaded\n");
	return 0;

poweroff_work_queue_create_failed:
	free_irq (gpio_to_irq(TT_VGPIO_ON_OFF), strasbourg_ps_pdev);
request_irq_failed:
	gpio_free (TT_VGPIO_ON_OFF);
gpio_alloc_failed:
	wake_lock_destroy(&strasbourg_ps_wake_lock);
usb_failed:
	power_supply_unregister(&strasbourg_ps_usb);
ac_failed:
	power_supply_unregister(&strasbourg_ps_ac);
bat_failed:
	power_supply_unregister(&strasbourg_ps_bat);
	platform_device_unregister(strasbourg_ps_pdev);
	return ret;
}
Example #24
0
int gpio_event_matrix_func(struct gpio_event_input_devs *input_devs,
	struct gpio_event_info *info, void **data, int func)
{
	int i;
	int err;
	int key_count;
	struct gpio_kp *kp;
	struct gpio_event_matrix_info *mi;

	mi = container_of(info, struct gpio_event_matrix_info, info);
	if (func == GPIO_EVENT_FUNC_SUSPEND || func == GPIO_EVENT_FUNC_RESUME) {
		/* TODO: disable scanning */
		return 0;
	}

	if (func == GPIO_EVENT_FUNC_INIT) {
		if (mi->keymap == NULL ||
		   mi->input_gpios == NULL ||
		   mi->output_gpios == NULL) {
			err = -ENODEV;
			pr_err("gpiomatrix: Incomplete pdata\n");
			goto err_invalid_platform_data;
		}
		printk("[%s:%d] hw rev = %d\n", __func__, __LINE__, board_hw_revision);

#if defined(CONFIG_MACH_EUROPA)
		if(board_hw_revision >= 3)
		{
			mi->keymap[(0)*mi->ninputs + (1)] = KEY_RESERVED;
			mi->keymap[(3)*mi->ninputs + (1)] = KEY_VOLUMEDOWN;
			mi->keymap[(3)*mi->ninputs + (4)] = KEY_VOLUMEUP;

			if(board_hw_revision >= 4)
			{
				mi->input_gpios[4] = 76;
			}
		}
#endif
#if defined(CONFIG_MACH_CALLISTO)
		// hsil
		input_set_capability(input_devs->dev[0], EV_SW, SW_LID);
#endif
		key_count = mi->ninputs * mi->noutputs;

		*data = kp = kzalloc(sizeof(*kp) + sizeof(kp->keys_pressed[0]) *
				     BITS_TO_LONGS(key_count), GFP_KERNEL);
		if (kp == NULL) {
			err = -ENOMEM;
			pr_err("gpiomatrix: Failed to allocate private data\n");
			goto err_kp_alloc_failed;
		}
		kp->input_devs = input_devs;
		kp->keypad_info = mi;
		for (i = 0; i < key_count; i++) {
			unsigned short keyentry = KEY_HW_REV(i); //mi->keymap[i];
			unsigned short keycode = keyentry & MATRIX_KEY_MASK;
			unsigned short dev = keyentry >> MATRIX_CODE_BITS;
			if (dev >= input_devs->count) {
				pr_err("gpiomatrix: bad device index %d >= "
					"%d for key code %d\n",
					dev, input_devs->count, keycode);
				err = -EINVAL;
				goto err_bad_keymap;
			}
			if (keycode && keycode <= KEY_MAX)
				input_set_capability(input_devs->dev[dev],
							EV_KEY, keycode);
		}
		input_set_capability(input_devs->dev[0],EV_KEY, KEY_END); // for COOPER

#if defined(CONFIG_MACH_COOPER) || defined(CONFIG_MACH_BENI) || defined(CONFIG_MACH_TASS)
#if defined(CONFIG_KERNEL_SEC_MMICHECK)
		for(i = 0 ; i < ARRAY_SIZE(mmi_keycode) ; i++)
			input_set_capability(input_devs->dev[0],EV_KEY, mmi_keycode[i]); // for COOPER			
#endif
#endif
		for (i = 0; i < mi->noutputs; i++) {
			if (gpio_cansleep(mi->output_gpios[i])) {
				pr_err("gpiomatrix: unsupported output gpio %d,"
					" can sleep\n", mi->output_gpios[i]);
				err = -EINVAL;
				goto err_request_output_gpio_failed;
			}
			err = gpio_request(mi->output_gpios[i], "gpio_kp_out");
			if (err) {
				pr_err("gpiomatrix: gpio_request failed for "
					"output %d\n", mi->output_gpios[i]);
				goto err_request_output_gpio_failed;
			}
			if (mi->flags & GPIOKPF_DRIVE_INACTIVE)
				err = gpio_direction_output(mi->output_gpios[i],
					!(mi->flags & GPIOKPF_ACTIVE_HIGH));
			else
				err = gpio_direction_input(mi->output_gpios[i]);
			if (err) {
				pr_err("gpiomatrix: gpio_configure failed for "
					"output %d\n", mi->output_gpios[i]);
				goto err_output_gpio_configure_failed;
			}
		}
		for (i = 0; i < mi->ninputs; i++) {
			err = gpio_request(mi->input_gpios[i], "gpio_kp_in");
			if (err) {
				pr_err("gpiomatrix: gpio_request failed for "
					"input %d\n", mi->input_gpios[i]);
				goto err_request_input_gpio_failed;
			}
			err = gpio_direction_input(mi->input_gpios[i]);
			if (err) {
				pr_err("gpiomatrix: gpio_direction_input failed"
					" for input %d\n", mi->input_gpios[i]);
				goto err_gpio_direction_input_failed;
			}
		}
		
		// for COOPER
		err = gpio_direction_input(GPIO_POWERKEY);
		if (err) {
			pr_err("gpiomatrix: gpio_direction_input failed"
				" for input GPIO_POWERKEY %d\n", GPIO_POWERKEY );
			goto err_gpio_direction_input_failed;
		}

		kp->current_output = mi->noutputs;
		kp->key_state_changed = 1;

		hrtimer_init(&kp->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
		kp->timer.function = gpio_keypad_timer_func;
		wake_lock_init(&kp->wake_lock, WAKE_LOCK_SUSPEND, "gpio_kp");
		err = gpio_keypad_request_irqs(kp);
		kp->use_irq = err == 0;

		pr_info("GPIO Matrix Keypad Driver: Start keypad matrix for "
			"%s%s in %s mode\n", input_devs->dev[0]->name,
			(input_devs->count > 1) ? "..." : "",
			kp->use_irq ? "interrupt" : "polling");

		if (kp->use_irq)
			wake_lock(&kp->wake_lock);
		hrtimer_start(&kp->timer, ktime_set(0, 0), HRTIMER_MODE_REL);

		return 0;
	}

	err = 0;
	kp = *data;

	if (kp->use_irq)
		for (i = mi->noutputs - 1; i >= 0; i--)
			free_irq(gpio_to_irq(mi->input_gpios[i]), kp);

	hrtimer_cancel(&kp->timer);
	wake_lock_destroy(&kp->wake_lock);
	for (i = mi->noutputs - 1; i >= 0; i--) {
err_gpio_direction_input_failed:
		gpio_free(mi->input_gpios[i]);
err_request_input_gpio_failed:
		;
	}
	for (i = mi->noutputs - 1; i >= 0; i--) {
err_output_gpio_configure_failed:
		gpio_free(mi->output_gpios[i]);
err_request_output_gpio_failed:
		;
	}
err_bad_keymap:
	kfree(kp);
err_kp_alloc_failed:
err_invalid_platform_data:
	return err;
}
Example #25
0
static int mw100_probe(struct platform_device *pdev)
{
	struct rk29_mw100_data *pdata = gpdata = pdev->dev.platform_data;
	struct modem_dev *mw100_data = NULL;
	int result, irq = 0;	

	gpio_request(pdata->bp_power,"bp_power");
	gpio_request(pdata->bp_reset,"bp_reset");
	gpio_request(pdata->bp_wakeup_ap,"bp_wakeup_ap");
	gpio_request(pdata->ap_wakeup_bp,"ap_wakeup_bp");
	gpio_set_value(pdata->modem_power_en, GPIO_HIGH);
	msleep(1000);
	gpio_direction_output(pdata->bp_reset,GPIO_LOW);
	mdelay(120);
	gpio_set_value(pdata->bp_reset, GPIO_HIGH);
	
	gpio_set_value(pdata->ap_wakeup_bp, GPIO_HIGH);
	gpio_direction_output(pdata->ap_wakeup_bp,GPIO_HIGH);	
	
	gpio_set_value(pdata->bp_power, GPIO_HIGH);
	gpio_direction_output(pdata->bp_power,GPIO_HIGH);	
	mdelay(120);
	gpio_set_value(pdata->bp_power, GPIO_LOW);
	gpio_direction_output(pdata->bp_power,GPIO_LOW);	
	
	mw100_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL);
	if(mw100_data == NULL){
		printk("failed to request mw100_data\n");
		goto err2;
	}
	platform_set_drvdata(pdev, mw100_data);	
	
	gpio_direction_input(pdata->bp_wakeup_ap);
	irq	= gpio_to_irq(pdata->bp_wakeup_ap);
	if(irq < 0){
		gpio_free(pdata->bp_wakeup_ap);
		printk("failed to request bp_wakeup_ap\n");
	}
	
	bp_wakeup_ap_irq = irq;
	
	result = request_irq(irq, detect_irq_handler, IRQ_BB_WAKEUP_AP_TRIGGER, "bp_wakeup_ap", NULL);
	if (result < 0) {
		printk("%s: request_irq(%d) failed\n", __func__, irq);
		gpio_free(pdata->bp_wakeup_ap);
		goto err0;
	}

	enable_irq_wake(bp_wakeup_ap_irq); 

	wake_lock_init(&bp_wakelock, WAKE_LOCK_SUSPEND, "bp_resume");

	result = misc_register(&mw100_misc);
	if(result){
		MODEMDBG("misc_register err\n");
	}	
	return result;
err0:
	gpio_free(pdata->bp_wakeup_ap);
err2:
	kfree(mw100_data);
	return 0;
}
Example #26
0
static struct i2c_driver apds9130_driver;
static int __devinit apds9130_probe(struct i2c_client *client,
				   const struct i2c_device_id *id)
{
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct apds9130_data *data;
	int err = 0;

	printk(KERN_INFO "%s %d\n ",__func__,__LINE__);

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) {
		err = -EIO;
		printk("apds9130 probe failed due to  I2C_FUNC_SMBUS_BYTE. Ret = %d\n",err);
		goto exit;
	}

	data = kzalloc(sizeof(struct apds9130_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		printk("apds9130 probe failed due to no memory %d\n",err);
		goto exit;
	}

	data->client = client;
	apds9130_i2c_client = client;

	i2c_set_clientdata(client, data);
	wake_lock_init(&data->ps_wlock, WAKE_LOCK_SUSPEND, "proxi_wakelock");

	data->enable = 0;	/* default mode is standard */
	data->ps_threshold = APDS9130_PS_DETECTION_THRESHOLD;
	data->ps_hysteresis_threshold = APDS9130_PS_HSYTERESIS_THRESHOLD;
	data->ps_detection = 0;	/* default to no detection */
	data->enable_ps_sensor = 0;	// default to 0
#if defined(APDS9130_PROXIMITY_CAL)
	data->cross_talk=PS_DEFAULT_CROSS_TALK;
#endif

	mutex_init(&data->update_lock);

	/* Initialize the APDS-9130 chip */
	err = apds9130_init_client(client);
	if (err < 0){
		printk("apds9130 probe failed due to init client Ret = %d\n",err);
		goto exit_kfree;
	}

	INIT_DELAYED_WORK(&data->dwork, apds9130_work_handler);

	if (request_irq(client->irq, apds9130_interrupt, IRQF_DISABLED|IRQ_TYPE_EDGE_FALLING,
		APDS9130_DRV_NAME, (void *)client)) {
		printk(KERN_INFO"%s Could not allocate APDS9130_INT %d !\n", __func__,client->irq);

		goto exit_kfree;
	}

	enable_irq_wake(client->irq);


	printk(KERN_INFO"%s interrupt is hooked\n", __func__);

	data->input_dev_ps = input_allocate_device();
	if (!data->input_dev_ps) {
		err = -ENOMEM;
		printk(KERN_INFO"Failed to allocate input device ps\n");
		goto exit_free_irq;
	}

	set_bit(EV_ABS, data->input_dev_ps->evbit);

	input_set_abs_params(data->input_dev_ps, ABS_DISTANCE, 0, 1, 0, 0);

	data->input_dev_ps->name = "proximity";

	err = input_register_device(data->input_dev_ps);
	if (err) {
		err = -ENOMEM;
		printk(KERN_INFO"Unable to register input device ps: %s\n",
		       data->input_dev_ps->name);
		goto exit_free_dev_ps;
	}

	data->sw_mode = PROX_STAT_OPERATING;

	/* Register sysfs hooks */
	err = sysfs_create_group(&client->dev.kobj, &apds9130_attr_group);
	if (err)
		goto exit_unregister_dev_ps;

	printk(KERN_INFO"%s support ver. %s enabled\n", __func__, DRIVER_VERSION);

	return 0;


//                                                                                                                  
exit_unregister_dev_ps:
	input_unregister_device(data->input_dev_ps);
exit_free_dev_ps:
	input_free_device(data->input_dev_ps);
exit_free_irq:
	free_irq(client->irq, client);
exit_kfree:
//                                                                                        
	wake_lock_destroy(&data->ps_wlock);
	mutex_destroy(&data->update_lock);
//                                         
	kfree(data);
exit:
Example #27
0
static int __devinit pmic8xxx_pwrkey_probe(struct platform_device *pdev)
{
	struct input_dev *pwr;
	int key_release_irq = platform_get_irq(pdev, 0);
	int key_press_irq = platform_get_irq(pdev, 1);
	int err;
	unsigned int delay;
	u8 pon_cntl;
	struct pmic8xxx_pwrkey *pwrkey;
	const struct pm8xxx_pwrkey_platform_data *pdata =
					dev_get_platdata(&pdev->dev);

	if (!pdata) {
		dev_err(&pdev->dev, "power key platform data not supplied\n");
		return -EINVAL;
	}

	/* Valid range of pwr key trigger delay is 1/64 sec to 2 seconds. */
	if (pdata->kpd_trigger_delay_us > USEC_PER_SEC * 2 ||
		pdata->kpd_trigger_delay_us < USEC_PER_SEC / 64) {
		dev_err(&pdev->dev, "invalid power key trigger delay\n");
		return -EINVAL;
	}

	pwrkey = kzalloc(sizeof(*pwrkey), GFP_KERNEL);
	if (!pwrkey)
		return -ENOMEM;

	pwrkey->pdata = pdata;

	pwr = input_allocate_device();
	if (!pwr) {
		dev_dbg(&pdev->dev, "Can't allocate power button\n");
		err = -ENOMEM;
		goto free_pwrkey;
	}

	input_set_capability(pwr, EV_KEY, KEY_POWER);

	pwr->name = "pmic8xxx_pwrkey";
	pwr->phys = "pmic8xxx_pwrkey/input0";
	pwr->dev.parent = &pdev->dev;

	delay = (pdata->kpd_trigger_delay_us << 6) / USEC_PER_SEC;
	delay = ilog2(delay);

	err = pm8xxx_readb(pdev->dev.parent, PON_CNTL_1, &pon_cntl);
	if (err < 0) {
		dev_err(&pdev->dev, "failed reading PON_CNTL_1 err=%d\n", err);
		goto free_input_dev;
	}

	pon_cntl &= ~PON_CNTL_TRIG_DELAY_MASK;
	pon_cntl |= (delay & PON_CNTL_TRIG_DELAY_MASK);
	if (pdata->pull_up)
		pon_cntl |= PON_CNTL_PULL_UP;
	else
		pon_cntl &= ~PON_CNTL_PULL_UP;

	err = pm8xxx_writeb(pdev->dev.parent, PON_CNTL_1, pon_cntl);
	if (err < 0) {
		dev_err(&pdev->dev, "failed writing PON_CNTL_1 err=%d\n", err);
		goto free_input_dev;
	}

	err = input_register_device(pwr);
	if (err) {
		dev_dbg(&pdev->dev, "Can't register power key: %d\n", err);
		goto free_input_dev;
	}

	pwrkey->key_press_irq = key_press_irq;
	pwrkey->pwr = pwr;

	platform_set_drvdata(pdev, pwrkey);

	err = request_any_context_irq(key_press_irq, pwrkey_press_irq,
		IRQF_TRIGGER_RISING, "pmic8xxx_pwrkey_press", pwrkey);
	if (err < 0) {
		dev_dbg(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n",
				 key_press_irq, err);
		goto unreg_input_dev;
	}

	err = request_any_context_irq(key_release_irq, pwrkey_release_irq,
		 IRQF_TRIGGER_RISING, "pmic8xxx_pwrkey_release", pwrkey);
	if (err < 0) {
		dev_dbg(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n",
				 key_release_irq, err);

		goto free_press_irq;
	}

	wake_lock_init(&pwrkey_wakelock,WAKE_LOCK_SUSPEND,"pmic8xxx_pwrkey");
	device_init_wakeup(&pdev->dev, pdata->wakeup);

	return 0;

free_press_irq:
	free_irq(key_press_irq, NULL);
unreg_input_dev:
	platform_set_drvdata(pdev, NULL);
	input_unregister_device(pwr);
	pwr = NULL;
free_input_dev:
	input_free_device(pwr);
free_pwrkey:
	kfree(pwrkey);
	return err;
}
Example #28
0
static __devinit int max8998_charger_probe(struct platform_device *pdev)
{
	struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
	struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
	struct chg_data *chg;
	struct i2c_client *i2c = iodev->i2c;
	int ret = 0;

	pr_info("%s : MAX8998 Charger Driver Loading\n", __func__);

	chg = kzalloc(sizeof(*chg), GFP_KERNEL);
	if (!chg)
		return -ENOMEM;

	chg->iodev = iodev;
	chg->pdata = pdata->charger;

	if (!chg->pdata || !chg->pdata->adc_table) {
		pr_err("%s : No platform data & adc_table supplied\n", __func__);
		ret = -EINVAL;
		goto err_bat_table;
	}

	chg->psy_bat.name = "battery",
	chg->psy_bat.type = POWER_SUPPLY_TYPE_BATTERY,
	chg->psy_bat.properties = max8998_battery_props,
	chg->psy_bat.num_properties = ARRAY_SIZE(max8998_battery_props),
	chg->psy_bat.get_property = s3c_bat_get_property,

	chg->psy_usb.name = "usb",
	chg->psy_usb.type = POWER_SUPPLY_TYPE_USB,
	chg->psy_usb.supplied_to = supply_list,
	chg->psy_usb.num_supplicants = ARRAY_SIZE(supply_list),
	chg->psy_usb.properties = s3c_power_properties,
	chg->psy_usb.num_properties = ARRAY_SIZE(s3c_power_properties),
	chg->psy_usb.get_property = s3c_usb_get_property,

	chg->psy_ac.name = "ac",
	chg->psy_ac.type = POWER_SUPPLY_TYPE_MAINS,
	chg->psy_ac.supplied_to = supply_list,
	chg->psy_ac.num_supplicants = ARRAY_SIZE(supply_list),
	chg->psy_ac.properties = s3c_power_properties,
	chg->psy_ac.num_properties = ARRAY_SIZE(s3c_power_properties),
	chg->psy_ac.get_property = s3c_ac_get_property,

	chg->present = 1;
	chg->polling_interval = POLLING_INTERVAL;
	chg->bat_info.batt_health = POWER_SUPPLY_HEALTH_GOOD;
	chg->bat_info.batt_is_full = false;
	chg->set_charge_timeout = false;

	chg->cable_status = CABLE_TYPE_NONE;

	mutex_init(&chg->mutex);

	platform_set_drvdata(pdev, chg);

	ret = max8998_update_reg(i2c, MAX8998_REG_CHGR1, /* disable */
		(0x3 << MAX8998_SHIFT_RSTR), MAX8998_MASK_RSTR);
	if (ret < 0)
		goto err_kfree;

	ret = max8998_update_reg(i2c, MAX8998_REG_CHGR2, /* 6 Hr */
		(0x2 << MAX8998_SHIFT_FT), MAX8998_MASK_FT);
	if (ret < 0)
		goto err_kfree;

	ret = max8998_update_reg(i2c, MAX8998_REG_CHGR2, /* 4.2V */
		(0x0 << MAX8998_SHIFT_BATTSL), MAX8998_MASK_BATTSL);
	if (ret < 0)
		goto err_kfree;

	ret = max8998_update_reg(i2c, MAX8998_REG_CHGR2, /* 105c */
		(0x0 << MAX8998_SHIFT_TMP), MAX8998_MASK_TMP);
	if (ret < 0)
		goto err_kfree;

	pr_info("%s : pmic interrupt registered\n", __func__);
	ret = max8998_write_reg(i2c, MAX8998_REG_IRQM1,
		~(MAX8998_MASK_DCINR | MAX8998_MASK_DCINF));
	if (ret < 0)
		goto err_kfree;

	ret = max8998_write_reg(i2c, MAX8998_REG_IRQM2, 0xFF);
	if (ret < 0)
		goto err_kfree;

	ret = max8998_write_reg(i2c, MAX8998_REG_IRQM3, ~0x4);
	if (ret < 0)
		goto err_kfree;

	ret = max8998_write_reg(i2c, MAX8998_REG_IRQM4, 0xFF);
	if (ret < 0)
		goto err_kfree;

	wake_lock_init(&chg->vbus_wake_lock, WAKE_LOCK_SUSPEND,
		"vbus_present");
	wake_lock_init(&chg->work_wake_lock, WAKE_LOCK_SUSPEND,
		"max8998-charger");

	INIT_WORK(&chg->bat_work, s3c_bat_work);

	chg->monitor_wqueue =
		create_freezable_workqueue(dev_name(&pdev->dev));
	if (!chg->monitor_wqueue) {
		pr_err("Failed to create freezeable workqueue\n");
		ret = -ENOMEM;
		goto err_wake_lock;
	}

	chg->last_poll = alarm_get_elapsed_realtime();
	alarm_init(&chg->alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
		s3c_battery_alarm);

	check_lpm_charging_mode(chg);

	/* init power supplier framework */
	ret = power_supply_register(&pdev->dev, &chg->psy_bat);
	if (ret) {
		pr_err("Failed to register power supply psy_bat\n");
		goto err_wqueue;
	}

	ret = power_supply_register(&pdev->dev, &chg->psy_usb);
	if (ret) {
		pr_err("Failed to register power supply psy_usb\n");
		goto err_supply_unreg_bat;
	}

	ret = power_supply_register(&pdev->dev, &chg->psy_ac);
	if (ret) {
		pr_err("Failed to register power supply psy_ac\n");
		goto err_supply_unreg_usb;
	}

	ret = request_threaded_irq(iodev->i2c->irq, NULL,
			max8998_int_work_func,
			IRQF_TRIGGER_FALLING, "max8998-charger", chg);
	if (ret) {
		pr_err("%s : Failed to request pmic irq\n", __func__);
		goto err_supply_unreg_ac;
	}

	ret = enable_irq_wake(iodev->i2c->irq);
	if (ret) {
		pr_err("Failed to enable pmic irq wake\n");
		goto err_irq;
	}

	ret = s3c_bat_create_attrs(chg->psy_bat.dev);
	if (ret) {
		pr_err("%s : Failed to create_attrs\n", __func__);
		goto err_irq;
	}

	chg->callbacks.set_cable = max8998_set_cable;
	if (chg->pdata->register_callbacks)
		chg->pdata->register_callbacks(&chg->callbacks);

	wake_lock(&chg->work_wake_lock);
	queue_work(chg->monitor_wqueue, &chg->bat_work);

	return 0;

err_irq:
	free_irq(iodev->i2c->irq, NULL);
err_supply_unreg_ac:
	power_supply_unregister(&chg->psy_ac);
err_supply_unreg_usb:
	power_supply_unregister(&chg->psy_usb);
err_supply_unreg_bat:
	power_supply_unregister(&chg->psy_bat);
err_wqueue:
	destroy_workqueue(chg->monitor_wqueue);
	cancel_work_sync(&chg->bat_work);
	alarm_cancel(&chg->alarm);
err_wake_lock:
	wake_lock_destroy(&chg->work_wake_lock);
	wake_lock_destroy(&chg->vbus_wake_lock);
err_kfree:
	mutex_destroy(&chg->mutex);
err_bat_table:
	kfree(chg);
	return ret;
}
Example #29
0
static int __devinit csid_probe(struct platform_device *pdev)
{
	struct csid_device *new_csid_dev;
	uint32_t csi_vdd_voltage = 0;
	int rc = 0;
	new_csid_dev = kzalloc(sizeof(struct csid_device), GFP_KERNEL);
	if (!new_csid_dev) {
		pr_err("%s: no enough memory\n", __func__);
		return -ENOMEM;
	}

	v4l2_subdev_init(&new_csid_dev->msm_sd.sd, &msm_csid_subdev_ops);
	v4l2_set_subdevdata(&new_csid_dev->msm_sd.sd, new_csid_dev);
	platform_set_drvdata(pdev, &new_csid_dev->msm_sd.sd);
	mutex_init(&new_csid_dev->mutex);

	if (pdev->dev.of_node) {
		rc = of_property_read_u32((&pdev->dev)->of_node,
			"cell-index", &pdev->id);
		if (rc < 0) {
			pr_err("%s:%d failed to read cell-index\n", __func__,
				__LINE__);
			goto csid_no_resource;
		}
		CDBG("%s device id %d\n", __func__, pdev->id);

		rc = of_property_read_u32((&pdev->dev)->of_node,
			"qcom,csi-vdd-voltage", &csi_vdd_voltage);
		if (rc < 0) {
			pr_err("%s:%d failed to read qcom,csi-vdd-voltage\n",
				__func__, __LINE__);
			goto csid_no_resource;
		}
		CDBG("%s:%d reading mipi_csi_vdd is %d\n", __func__, __LINE__,
			csi_vdd_voltage);

		csid_vreg_info[0].min_voltage = csi_vdd_voltage;
		csid_vreg_info[0].max_voltage = csi_vdd_voltage;
	}

	new_csid_dev->mem = platform_get_resource_byname(pdev,
					IORESOURCE_MEM, "csid");
	if (!new_csid_dev->mem) {
		pr_err("%s: no mem resource?\n", __func__);
		rc = -ENODEV;
		goto csid_no_resource;
	}
	new_csid_dev->irq = platform_get_resource_byname(pdev,
					IORESOURCE_IRQ, "csid");
	if (!new_csid_dev->irq) {
		pr_err("%s: no irq resource?\n", __func__);
		rc = -ENODEV;
		goto csid_no_resource;
	}
	new_csid_dev->io = request_mem_region(new_csid_dev->mem->start,
		resource_size(new_csid_dev->mem), pdev->name);
	if (!new_csid_dev->io) {
		pr_err("%s: no valid mem region\n", __func__);
		rc = -EBUSY;
		goto csid_no_resource;
	}

	new_csid_dev->pdev = pdev;
	new_csid_dev->msm_sd.sd.internal_ops = &msm_csid_internal_ops;
	new_csid_dev->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
	snprintf(new_csid_dev->msm_sd.sd.name,
			ARRAY_SIZE(new_csid_dev->msm_sd.sd.name), "msm_csid");
	media_entity_init(&new_csid_dev->msm_sd.sd.entity, 0, NULL, 0);
	new_csid_dev->msm_sd.sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
	new_csid_dev->msm_sd.sd.entity.group_id = MSM_CAMERA_SUBDEV_CSID;
	new_csid_dev->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0x5;
	msm_sd_register(&new_csid_dev->msm_sd);

	rc = request_irq(new_csid_dev->irq->start, msm_csid_irq,
		IRQF_TRIGGER_RISING, "csid", new_csid_dev);
	if (rc < 0) {
		release_mem_region(new_csid_dev->mem->start,
			resource_size(new_csid_dev->mem));
		pr_err("%s: irq request fail\n", __func__);
		rc = -EBUSY;
		goto csid_no_resource;
	}
	disable_irq(new_csid_dev->irq->start);
	if (rc < 0) {
		release_mem_region(new_csid_dev->mem->start,
			resource_size(new_csid_dev->mem));
		pr_err("%s Error registering irq ", __func__);
		goto csid_no_resource;
	}

	new_csid_dev->csid_state = CSID_POWER_DOWN;
	pr_err(" %s:%d CSID_POWER_DOWN %d \n",__func__,__LINE__,new_csid_dev->csid_state);

/* LGE_CHANGE_S [[email protected]][20130625] : To enter the deep sleep after finish camera open , for google talk */
	wake_lock_init(&new_csid_dev->csid_wake_lock, WAKE_LOCK_SUSPEND, "csid_wake_lock");
/* LGE_CHANGE_E [[email protected]][20130625] : To enter the deep sleep after finish camera open , for google talk */
	return 0;

csid_no_resource:
	mutex_destroy(&new_csid_dev->mutex);
	kfree(new_csid_dev);
	return 0;
}
static int __devinit bq51051b_wlc_probe(struct platform_device *pdev)
{
	int rc = 0;
	struct bq51051b_wlc_chip *chip;
	const struct bq51051b_wlc_platform_data *pdata =
		pdev->dev.platform_data;

	WLC_DBG_INFO("probe\n");

	if (!pdata) {
		pr_err("wlc: missing platform data\n");
		return -ENODEV;
	}

	chip = kzalloc(sizeof(struct bq51051b_wlc_chip), GFP_KERNEL);
	if (!chip) {
		pr_err("wlc: Cannot allocate bq51051b_wlc_chip\n");
		return -ENOMEM;
	}

	chip->dev = &pdev->dev;

	chip->active_n_gpio = pdata->active_n_gpio;
	chip->wlc_is_plugged = pdata->wlc_is_plugged;

	rc = bq51051b_wlc_hw_init(chip);
	if (rc) {
		pr_err("wlc: couldn't init hardware rc = %d\n", rc);
		goto free_chip;
	}

	chip->wireless_psy.name = "wireless";
	chip->wireless_psy.type = POWER_SUPPLY_TYPE_WIRELESS;
	chip->wireless_psy.supplied_to = pm_power_supplied_to;
	chip->wireless_psy.num_supplicants = ARRAY_SIZE(pm_power_supplied_to);
	chip->wireless_psy.properties = pm_power_props_wireless;
	chip->wireless_psy.num_properties = ARRAY_SIZE(pm_power_props_wireless);
	chip->wireless_psy.get_property = pm_power_get_property_wireless;

	rc = power_supply_register(chip->dev, &chip->wireless_psy);
	if (rc < 0) {
		pr_err("wlc: power_supply_register wireless failed rx = %d\n",
			      rc);
		goto free_chip;
	}

	platform_set_drvdata(pdev, chip);
	the_chip = chip;

	INIT_WORK(&chip->wireless_interrupt_work, wireless_interrupt_worker);
	wake_lock_init(&chip->wireless_chip_wake_lock, WAKE_LOCK_SUSPEND,
		       "bq51051b_wireless_chip");

	/* For Booting Wireless_charging and For Power Charging Logo In Wireless Charging */
	if (chip->wlc_is_plugged())
		wireless_set(chip);

	return 0;

free_chip:
	kfree(chip);
	return rc;
}