static int cardhu_nct1008_init(void)
{
	int nct1008_port = -1;
	int ret;
#ifdef CONFIG_TEGRA_EDP_LIMITS
	const struct tegra_edp_limits *z;
	int zones_sz;
	int i;
	bool throttle_ok = false;
#endif

	if ((board_info.board_id == BOARD_E1198) ||
		(board_info.board_id == BOARD_E1291) ||
		(board_info.board_id == BOARD_PM269)) {
		nct1008_port = TEGRA_GPIO_PCC2;
	} else if ((board_info.board_id == BOARD_E1186) ||
		(board_info.board_id == BOARD_E1187) ||
		(board_info.board_id == BOARD_E1256)) {
		/* FIXME: seems to be conflicting with usb3 vbus on E1186 */
		/* nct1008_port = TEGRA_GPIO_PH7; */
	}
	nct1008_port = TEGRA_GPIO_PCC2;

	if (nct1008_port >= 0) {
		/* FIXME: enable irq when throttling is supported */
		cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);

		ret = gpio_request(nct1008_port, "temp_alert");
		if (ret < 0)
			return ret;

		ret = gpio_direction_input(nct1008_port);
		if (ret < 0)
			gpio_free(nct1008_port);
		else
			tegra_gpio_enable(nct1008_port);
	}

#ifdef CONFIG_TEGRA_EDP_LIMITS
	tegra_get_cpu_edp_limits(&z, &zones_sz);
	zones_sz = min(zones_sz, MAX_ZONES);
	for (i = 0; i < zones_sz; i++) {
		cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
		if (cardhu_nct1008_pdata.thermal_zones[i] ==
		    cardhu_nct1008_pdata.throttling_ext_limit) {
			throttle_ok = true;
		}
	}

	if (throttle_ok != true)
		pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
			" as it is NOT one of the EDP points\n",
			__func__, cardhu_nct1008_pdata.throttling_ext_limit);
	else
		pr_info("%s: Throttling limit %dC OK\n",
			__func__, cardhu_nct1008_pdata.throttling_ext_limit);

	cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
#endif
	return ret;
}
Esempio n. 2
0
/*
 *  pin:    pin 0-9
 *  type:   NULL/IN/OUT/IRQ
 *  value:  
 *          IN:     value=0
 *          OUT:    value=0/1   reset value
 *          IRQ:    value={emun irq_trigger_type}
 */
static int config_pin(int n, enum pin_type type, int value) {

    int ret=-1;

    if(n<0 || n > 9 || type < 0 || type > 3 || value < 0 || value > 2) {
        printk("config pin params error\n");
        return -1;
    }

    printk("config pin n=%d type=%d value=%d\n", n, type, value);
    if(type == PIN_TYPE_NULL) {

        if(pin_type[n] == PIN_TYPE_IRQ) {
            if(n == 2) {
                free_irq(irq1, vdev_dev);
            } else if(n == 7) {
                free_irq(irq2, vdev_dev);
            } else if (n == 90) {
                free_irq(irq3, vdev_dev);
            }
        }
        ret = pinctrl_select_state(pinctrl, pin_in[n]);
        if(ret<0) {
            printk("pinctrl select state pin null[%d] error \n", n);
            return -1;
        }
        gpio_direction_input(pin[n]);
        pin_type[n] = PIN_TYPE_NULL;
        return 0;
    }

    if(type ==  PIN_TYPE_IN) {
        ret = pinctrl_select_state(pinctrl, pin_in[n]);
        if(ret<0) {
            printk("pinctrl select state pin in[%d] error\n", n);
            return -1;
        }
        gpio_direction_input(pin[n]);
        pin_type[n] = PIN_TYPE_IN;
        return 0;
    }

    if(type ==  PIN_TYPE_OUT) {
        ret = pinctrl_select_state(pinctrl, pin_out[n]);
        if(ret<0) {
            printk("pinctrl select state pin out[%d] error \n", n);
            return -1;
        }
        gpio_direction_output(pin[n], value>0?1:0);
        pin_type[n] = PIN_TYPE_OUT;
        return 0;
    }

    if(type ==  PIN_TYPE_IRQ && (n == 2 || n == 7 || n == 9)) {

        config_irq(n, value);
        pin_type[n] = PIN_TYPE_IRQ;
        return 0;
    }
    
    return ret;
}
static int __devinit mma8x5x_probe(struct i2c_client *client,
				   const struct i2c_device_id *id)
{
	int result, chip_id;
	struct input_dev *idev;
	struct mma8x5x_data *pdata;
	struct i2c_adapter *adapter;
	adapter = to_i2c_adapter(client->dev.parent);
	/* power on the device */
	result = mma8x5x_config_regulator(client, 1);
	if (result)
		goto err_power_on;

	result = i2c_check_functionality(adapter,
					 I2C_FUNC_SMBUS_BYTE |
					 I2C_FUNC_SMBUS_BYTE_DATA);
	if (!result)
		goto err_check_id;

	chip_id = i2c_smbus_read_byte_data(client, MMA8X5X_WHO_AM_I);

	if (!mma8x5x_check_id(chip_id)) {
		dev_err(&client->dev,
			"read chip ID 0x%x is not equal to 0x%x,0x%x,0x%x,0x%x,0x%x!\n",
			chip_id, MMA8451_ID, MMA8452_ID, MMA8453_ID,
			MMA8652_ID, MMA8653_ID);
		result = -EINVAL;
		goto err_check_id;
	}
	/* set the private data */
	pdata = kzalloc(sizeof(struct mma8x5x_data), GFP_KERNEL);
	if (!pdata) {
		result = -ENOMEM;
		dev_err(&client->dev, "alloc data memory error!\n");
		goto err_check_id;
	}

	if (client->dev.of_node) {
		result = mma8x5x_parse_dt(&client->dev, pdata);
		if (result)
			goto err_parse_dt;
	} else {
		pdata->position = CONFIG_SENSORS_MMA_POSITION;
		pdata->int_pin = -1;
		pdata->int_flags = 0;
	}

	/* Initialize the MMA8X5X chip */
	pdata->client = client;
	pdata->chip_id = chip_id;
	pdata->mode = MODE_2G;
	pdata->poll_delay = POLL_INTERVAL;

	mutex_init(&pdata->data_lock);
	i2c_set_clientdata(client, pdata);
	/* Initialize the MMA8X5X chip */
	mma8x5x_device_init(client);
	if (pdata->use_int) {
		if (pdata->int_pin >= 0)
			client->irq = gpio_to_irq(pdata->int_pin);

		if (gpio_is_valid(pdata->int_pin)) {
			result = gpio_request(pdata->int_pin,
				"mma8x5x_irq_gpio");
			if (result) {
				dev_err(&client->dev, "irq gpio(%d) request failed",
					pdata->int_pin);
				goto err_request_gpio;
			}
			result = gpio_direction_input(pdata->int_pin);
			if (result) {
				dev_err(&client->dev,
					"set_direction for irq gpio failed\n");
				goto err_set_gpio_direction;
			}
		}
		device_init_wakeup(&client->dev, true);
		enable_irq_wake(client->irq);
		result = request_threaded_irq(client->irq, NULL,
			mma8x5x_interrupt,
			IRQ_TYPE_EDGE_RISING | IRQF_ONESHOT | IRQF_NO_SUSPEND,
			ACCEL_INPUT_DEV_NAME, (void *)client);
		if (result) {
			dev_err(&client->dev, "Could not allocate irq(%d) !\n",
				client->irq);
			goto err_register_irq;
		}
		mma8x5x_device_int_init(client);
	} else {
		INIT_DELAYED_WORK(&pdata->dwork, mma8x5x_dev_poll);
	}
	idev = input_allocate_device();
	if (!idev) {
		result = -ENOMEM;
		dev_err(&client->dev, "alloc input device failed!\n");
		goto err_alloc_poll_device;
	}
	input_set_drvdata(idev, pdata);
	idev->name = ACCEL_INPUT_DEV_NAME;
	idev->uniq = mma8x5x_id2name(pdata->chip_id);
	idev->id.bustype = BUS_I2C;
	idev->evbit[0] = BIT_MASK(EV_ABS);
	input_set_abs_params(idev, ABS_X, -0x7fff, 0x7fff, 0, 0);
	input_set_abs_params(idev, ABS_Y, -0x7fff, 0x7fff, 0, 0);
	input_set_abs_params(idev, ABS_Z, -0x7fff, 0x7fff, 0, 0);
	result = input_register_device(idev);
	if (result) {
		dev_err(&client->dev, "register input device failed!\n");
		goto err_register_device;
	}
	pdata->idev = idev;

	result = sysfs_create_group(&idev->dev.kobj, &mma8x5x_attr_group);
	if (result) {
		dev_err(&client->dev, "create device file failed!\n");
		result = -EINVAL;
		goto err_create_sysfs;
	}
	pdata->cdev = sensors_cdev;
	pdata->cdev.min_delay = POLL_INTERVAL_MIN * 1000;
	pdata->cdev.delay_msec = pdata->poll_delay;
	pdata->cdev.sensors_enable = mma8x5x_enable_set;
	pdata->cdev.sensors_poll_delay = mma8x5x_poll_delay_set;
	result = sensors_classdev_register(&client->dev, &pdata->cdev);
	if (result) {
		dev_err(&client->dev, "create class device file failed!\n");
		result = -EINVAL;
		goto err_create_class_sysfs;
	}
	dev_info(&client->dev,
		"%s:mma8x5x device driver probe successfully, position =%d\n",
		__func__, pdata->position);

	return 0;
err_create_class_sysfs:
	sysfs_remove_group(&idev->dev.kobj, &mma8x5x_attr_group);
err_create_sysfs:
	input_unregister_device(idev);
err_register_device:
	input_free_device(idev);
err_alloc_poll_device:
err_register_irq:
	if (pdata->use_int)
		device_init_wakeup(&client->dev, false);
err_set_gpio_direction:
	if (gpio_is_valid(pdata->int_pin) && pdata->use_int)
		gpio_free(pdata->int_pin);
err_request_gpio:
err_parse_dt:
	kfree(pdata);
err_check_id:
	mma8x5x_config_regulator(client, 0);
err_power_on:
	return result;
}
static int ssp_parse_dt(struct device *dev,
	struct  ssp_data *data)
{
	struct device_node *np = dev->of_node;
	enum of_gpio_flags flags;
	int errorno = 0;

	data->mcu_int1 = of_get_named_gpio_flags(np, "ssp,mcu_int1-gpio",
		0, &flags);
	if (data->mcu_int1 < 0) {
		errorno = data->mcu_int1;
		goto dt_exit;
	}

	data->mcu_int2 = of_get_named_gpio_flags(np, "ssp,mcu_int2-gpio",
		0, &flags);
	if (data->mcu_int2 < 0) {
		errorno = data->mcu_int2;
		goto dt_exit;
	}

	data->ap_int = of_get_named_gpio_flags(np, "ssp,ap_int-gpio",
		0, &flags);
	if (data->ap_int < 0) {
		errorno = data->ap_int;
		goto dt_exit;
	}

	data->rst = of_get_named_gpio_flags(np, "ssp,rst-gpio",
		0, &flags);
	if (data->rst < 0) {
		errorno = data->rst ;
		goto dt_exit;
	}

	if (of_property_read_u32(np, "ssp,acc-position", &data->accel_position))
		data->accel_position = 0;

	if (of_property_read_u32(np, "ssp,mag-position", &data->mag_position))
		data->mag_position = 0;

	if (of_property_read_u32(np, "ssp,sns-combination", &data->sns_combination))
		data->sns_combination = 0;

	if (of_property_read_u32(np, "ssp,ap-rev", &data->ap_rev))
		data->ap_rev = 0;

	if (of_property_read_u32(np, "ssp,rotation-direction", &data->rot_direction))
		data->rot_direction = 0;

	errorno = gpio_request(data->mcu_int1, "mpu_ap_int1");
	if (errorno) {
		printk(KERN_ERR "failed to request MCU_INT2 for SSP\n");
		goto dt_exit;
	}

	errorno = gpio_direction_input(data->mcu_int1);
	if (errorno) {
		printk(KERN_ERR "failed to set mcu_int1 as input\n");
		goto dt_exit;
	}

	errorno = gpio_request(data->mcu_int2, "MCU_INT2");
	if (errorno) {
		printk(KERN_ERR "failed to request MCU_INT2 for SSP\n");
		goto dt_exit;
	}
	gpio_direction_input(data->mcu_int2);

	errorno = gpio_request(data->ap_int, "AP_MCU_INT");
	if (errorno) {
		printk(KERN_ERR "failed to request AP_INT for SSP\n");
		goto dt_exit;
	}
	gpio_direction_output(data->ap_int, 1);

	errorno = gpio_request(data->rst, "MCU_RST");
	if (errorno) {
		printk(KERN_ERR "failed to request MCU_RST for SSP\n");
		goto dt_exit;
	}
	gpio_direction_output(data->rst, 1);

	data->reg_hub = devm_regulator_get(dev, "hub_vreg");
	if (IS_ERR(data->reg_hub)) {
		pr_err("[SSP] could not get hub_vreg, %ld\n",
			PTR_ERR(data->reg_hub));
	} else {
		regulator_enable(data->reg_hub);
	}

	data->reg_sns= devm_regulator_get(dev, "psns_vreg");
	if (IS_ERR(data->reg_hub)) {
		pr_err("[SSP] could not get psns_vreg, %ld\n",
			PTR_ERR(data->reg_sns));
	} else {
		regulator_enable(data->reg_sns);
	}

dt_exit:
	return errorno;
}
static int mipi_dsi_on(struct platform_device *pdev)
{
	int ret = 0;
	u32 clk_rate;
	struct msm_fb_data_type *mfd;
	struct fb_info *fbi;
	struct fb_var_screeninfo *var;
	struct msm_panel_info *pinfo;
	struct mipi_panel_info *mipi;
	u32 hbp, hfp, vbp, vfp, hspw, vspw, width, height;
	u32 ystride, bpp, data;
	u32 dummy_xres, dummy_yres;
	int target_type = 0;
	u32 tmp;

	pr_debug("%s+:\n", __func__);

#if defined(CONFIG_ESD_ERR_FG_RECOVERY)
	pdev_for_esd = pdev;
#endif
	mfd = platform_get_drvdata(pdev);
	fbi = mfd->fbi;
	var = &fbi->var;
	pinfo = &mfd->panel_info;
	esc_byte_ratio = pinfo->mipi.esc_byte_ratio;

	if (mipi_dsi_pdata && mipi_dsi_pdata->power_common)
		mipi_dsi_pdata->power_common();

#if defined(CONFIG_SUPPORT_SECOND_POWER)
	if (mipi_dsi_pdata && mipi_dsi_pdata->panel_power_save)
		mipi_dsi_pdata->panel_power_save(1);
#endif

	if (system_rev == 6)
		mdelay(500);

	if (mipi_dsi_pdata && mipi_dsi_pdata->dsi_power_save)
		mipi_dsi_pdata->dsi_power_save(1);

	cont_splash_clk_ctrl(0);
	mipi_dsi_prepare_clocks();

	mipi_dsi_ahb_ctrl(1);

	clk_rate = mfd->fbi->var.pixclock;
	clk_rate = min(clk_rate, mfd->panel_info.clk_max);

	mipi_dsi_phy_ctrl(1);

	if (mdp_rev == MDP_REV_42 && mipi_dsi_pdata)
		target_type = mipi_dsi_pdata->target_type;

	mipi_dsi_phy_init(0, &(mfd->panel_info), target_type);

	mipi_dsi_clk_enable();

	MIPI_OUTP(MIPI_DSI_BASE + 0x114, 1);
	MIPI_OUTP(MIPI_DSI_BASE + 0x114, 0);

	hbp = var->left_margin;
	hfp = var->right_margin;
	vbp = var->upper_margin;
	vfp = var->lower_margin;
	hspw = var->hsync_len;
	vspw = var->vsync_len;
	width = mfd->panel_info.xres;
	height = mfd->panel_info.yres;

	mipi  = &mfd->panel_info.mipi;
	if (mfd->panel_info.type == MIPI_VIDEO_PANEL) {
		dummy_xres = mfd->panel_info.lcdc.xres_pad;
		dummy_yres = mfd->panel_info.lcdc.yres_pad;

		if (mdp_rev >= MDP_REV_41) {
			MIPI_OUTP(MIPI_DSI_BASE + 0x20,
				((hspw + hbp + width + dummy_xres) << 16 |
				(hspw + hbp)));
			MIPI_OUTP(MIPI_DSI_BASE + 0x24,
				((vspw + vbp + height + dummy_yres) << 16 |
				(vspw + vbp)));
			MIPI_OUTP(MIPI_DSI_BASE + 0x28,
				(vspw + vbp + height + dummy_yres +
					vfp - 1) << 16 | (hspw + hbp +
					width + dummy_xres + hfp - 1));
		} else {
			/* DSI_LAN_SWAP_CTRL */
			MIPI_OUTP(MIPI_DSI_BASE + 0x00ac, mipi->dlane_swap);

			MIPI_OUTP(MIPI_DSI_BASE + 0x20,
				((hbp + width + dummy_xres) << 16 | (hbp)));
			MIPI_OUTP(MIPI_DSI_BASE + 0x24,
				((vbp + height + dummy_yres) << 16 | (vbp)));
			MIPI_OUTP(MIPI_DSI_BASE + 0x28,
				(vbp + height + dummy_yres + vfp) << 16 |
					(hbp + width + dummy_xres + hfp));
		}

		MIPI_OUTP(MIPI_DSI_BASE + 0x2c, (hspw << 16));
		MIPI_OUTP(MIPI_DSI_BASE + 0x30, 0);
		MIPI_OUTP(MIPI_DSI_BASE + 0x34, (vspw << 16));

	} else {		/* command mode */
		if (mipi->dst_format == DSI_CMD_DST_FORMAT_RGB888)
			bpp = 3;
		else if (mipi->dst_format == DSI_CMD_DST_FORMAT_RGB666)
			bpp = 3;
		else if (mipi->dst_format == DSI_CMD_DST_FORMAT_RGB565)
			bpp = 2;
		else
			bpp = 3;	/* Default format set to RGB888 */

		ystride = width * bpp + 1;

		/* DSI_COMMAND_MODE_MDP_STREAM_CTRL */
		data = (ystride << 16) | (mipi->vc << 8) | DTYPE_DCS_LWRITE;
		MIPI_OUTP(MIPI_DSI_BASE + 0x5c, data);
		MIPI_OUTP(MIPI_DSI_BASE + 0x54, data);

		/* DSI_COMMAND_MODE_MDP_STREAM_TOTAL */
		data = height << 16 | width;
		MIPI_OUTP(MIPI_DSI_BASE + 0x60, data);
		MIPI_OUTP(MIPI_DSI_BASE + 0x58, data);
	}

	mipi_dsi_host_init(mipi);

	msleep(10);

	/* LP11 */
	tmp = MIPI_INP(MIPI_DSI_BASE + 0xA8);
	tmp &= ~(1<<28);
	MIPI_OUTP(MIPI_DSI_BASE + 0xA8, tmp);
	wmb();
	/* LP11 */

	usleep(5000);
	if (mipi_dsi_pdata && mipi_dsi_pdata->active_reset)
			mipi_dsi_pdata->active_reset(1); /* high */
	usleep(10000);

	/* always high */
	if (mipi->force_clk_lane_hs) {
		tmp = MIPI_INP(MIPI_DSI_BASE + 0xA8);
		tmp |= (1<<28);
		MIPI_OUTP(MIPI_DSI_BASE + 0xA8, tmp);
		wmb();
	}

	if (mdp_rev >= MDP_REV_41)
		mutex_lock(&mfd->dma->ov_mutex);
	else
		down(&mfd->dma->mutex);

	ret = panel_next_on(pdev);

	mipi_dsi_op_mode_config(mipi->mode);

	if (mfd->panel_info.type == MIPI_CMD_PANEL) {
		if (pinfo->lcd.vsync_enable) {
			if (pinfo->lcd.hw_vsync_mode && vsync_gpio >= 0) {
				if (mdp_rev >= MDP_REV_41) {
					if (gpio_request(vsync_gpio,
						"MDP_VSYNC") == 0)
						gpio_direction_input(
							vsync_gpio);
					else
						pr_err("%s: unable to \
							request gpio=%d\n",
							__func__, vsync_gpio);
				} else if (mdp_rev == MDP_REV_303) {
					if (!tlmm_settings && gpio_request(
						vsync_gpio, "MDP_VSYNC") == 0) {
						ret = gpio_tlmm_config(
							GPIO_CFG(
							vsync_gpio, 1,
							GPIO_CFG_INPUT,
							GPIO_CFG_PULL_DOWN,
							GPIO_CFG_2MA),
							GPIO_CFG_ENABLE);

						if (ret) {
							pr_err(
							"%s: unable to config \
							tlmm = %d\n",
							__func__, vsync_gpio);
						}
						tlmm_settings = TRUE;

						gpio_direction_input(
							vsync_gpio);
					} else {
						if (!tlmm_settings) {
							pr_err(
							"%s: unable to request \
							gpio=%d\n",
							__func__, vsync_gpio);
						}
					}
				}
Esempio n. 6
0
/**
 *  ti_tpd_probe
 */
static int __devinit ti_tpd_probe(struct pci_dev *pdev,
		const struct pci_device_id *ent)
{
	struct drm_device *dev = hdmi_priv ? hdmi_priv->dev : 0;
	struct drm_psb_private *dev_priv = dev ? psb_priv(dev) : 0;
	int ret = 0;

	PSB_DEBUG_ENTRY("\n");

	if (pdev->device != TI_TPD_PCI_DEVICE_ID) {
		DRM_ERROR("%s: pciid = 0x%x is not ti_tpd pciid.\n",
			  __func__, pdev->device);
		ret = -EINVAL;
		goto err0;
	}

	/* enable HDMI COMPANION CHIP device */
	ret = pci_enable_device(pdev);
	if (ret) {
		DRM_ERROR("%s:Fail to enable pci devices\n",
				__func__);
		goto err0;
	}

	ret = gpio_request(CLV_TI_HPD_GPIO_PIN, "ti_tpd_hdmi_hpd");
	if (ret) {
		DRM_ERROR("%s: Failed to request GPIO %d for kbd IRQ\n",
				__func__, CLV_TI_HPD_GPIO_PIN);
		goto err1;
	}

	ret = gpio_direction_input(CLV_TI_HPD_GPIO_PIN);
	if (ret) {
		DRM_ERROR("%s: Failed to set GPIO %d as input\n",
				__func__, CLV_TI_HPD_GPIO_PIN);
		goto err2;
	}

	ret = irq_set_irq_type(gpio_to_irq(CLV_TI_HPD_GPIO_PIN),
			IRQ_TYPE_EDGE_BOTH);
	if (ret) {
		DRM_ERROR("%s: Failed to set HDMI HPD IRQ type\n",
				__func__);
		goto err2;
	}

	if (dev_priv == NULL) {
		DRM_ERROR("%s: Invalid parameter", __func__);
		ret = -EINVAL;
		goto err2;
	}
	dev_priv->hpd_detect = create_freezable_workqueue("hpd_detect");
	if (dev_priv->hpd_detect == NULL) {
		DRM_ERROR("%s: Creating workqueue failed", __func__);
		ret = -ENOMEM;
		goto err2;
	}

	ret = request_irq(gpio_to_irq(CLV_TI_HPD_GPIO_PIN),
			hdmi_hpd_handler, IRQF_SHARED,
			"hdmi_hpd_handler", (void *)hdmi_priv);
	if (ret) {
		DRM_ERROR("%s: Can not register GPIO %d IRQ!\n",
				__func__, CLV_TI_HPD_GPIO_PIN);
		goto err3;
	}

	PSB_DEBUG_ENTRY("%s: Requested HDMI HPD IRQ"
			"sussessfully.\n", __func__);
	return ret;

err3:
	destroy_workqueue(dev_priv->hpd_detect);
err2:
	gpio_free(CLV_TI_HPD_GPIO_PIN);
err1:
	pci_disable_device(pdev);
err0:
	pci_dev_put(pdev);
	DRM_ERROR("%s: request_irq failed. ret = %d.\n", __func__, ret);
	return ret;
}
static void ventana_akm8975_init(void)
{
	tegra_gpio_enable(AKM8975_IRQ_GPIO);
	gpio_request(AKM8975_IRQ_GPIO, "akm8975");
	gpio_direction_input(AKM8975_IRQ_GPIO);
}
Esempio n. 8
0
void __init stx7108_configure_pci(struct stm_plat_pci_config *pci_conf)
{
	struct sysconf_field *sc;
	int i;

	/* LLA clocks have these horrible names... */
	pci_conf->clk_name = "CLKA_PCI";

	/* REQ0 is actually wired to REQ3 to work around NAND problems */
	pci_conf->req0_to_req3 = 1;
	BUG_ON(pci_conf->req_gnt[3] != PCI_PIN_UNUSED);

	/* Fill in the default values */
	if (!pci_conf->ad_override_default) {
		pci_conf->ad_threshold = 5;
		pci_conf->ad_read_ahead = 1;
		pci_conf->ad_chunks_in_msg = 0;
		pci_conf->ad_pcks_in_chunk = 0;
		pci_conf->ad_trigger_mode = 1;
		pci_conf->ad_max_opcode = 5;
		pci_conf->ad_posted = 1;
	}

	/* Copy over platform specific data to driver */
	stx7108_pci_device.dev.platform_data = pci_conf;

#if defined(CONFIG_PM)
#warning TODO: PCI Power Management
#endif
	/* Claim and power up the PCI cell */
	sc = sysconf_claim(SYS_CFG_BANK2, 30, 2, 2, "PCI_PWR_DWN_REQ");
	sysconf_write(sc, 0); /* We will need to stash this somewhere
				 for power management. */
	sc = sysconf_claim(SYS_STA_BANK2, 1, 2, 2, "PCI_PWR_DWN_GRANT");
	while (sysconf_read(sc))
		cpu_relax(); /* Loop until powered up */

	/* Configure the REQ/GNT[1..2], muxed with PIOs */
	for (i = 1; i <= 2; i++) {
		switch (pci_conf->req_gnt[i]) {
		case PCI_PIN_DEFAULT:
			if (stm_pad_claim(&stx7108_pci_reqgnt_pad_config[i],
					"PCI") == NULL) {
				printk(KERN_ERR "Failed to claim REQ/GNT%d "
						"pads!\n", i);
				BUG();
			}
			break;
		case PCI_PIN_UNUSED:
			/* Unused is unused - nothing to do */
			break;
		default:
			/* No alternative here... */
			BUG();
			break;
		}
	}

	/* Configure INTA..D interrupts */
	for (i = 0; i < 4; i++) {
		switch (pci_conf->pci_irq[i]) {
		case PCI_PIN_DEFAULT:
			if (stm_pad_claim(&stx7108_pci_int_pad_config[i],
						"PCI") == NULL) {
				printk(KERN_ERR "Failed to claim INT%c pad!\n",
						'A' + i);
				BUG();
			}
			set_irq_type(ILC_IRQ(122 + i), IRQ_TYPE_LEVEL_LOW);
			break;
		case PCI_PIN_ALTERNATIVE:
			/* There is no alternative here ;-) */
			BUG();
			break;
		default:
			/* Unused or interrupt number passed, nothing to do */
			break;
		}
	}

	/* Configure the SERR interrupt (if wired up) */
	switch (pci_conf->serr_irq) {
	case PCI_PIN_DEFAULT:
		if (gpio_request(STX7108_PIO_PCI_SERR, "PCI_SERR#") == 0) {
			gpio_direction_input(STX7108_PIO_PCI_SERR);
			pci_conf->serr_irq = gpio_to_irq(STX7108_PIO_PCI_SERR);
			set_irq_type(pci_conf->serr_irq, IRQ_TYPE_LEVEL_LOW);
		} else {
			printk(KERN_WARNING "%s(): Failed to claim PCI SERR# "
					"PIO!\n", __func__);
			pci_conf->serr_irq = PCI_PIN_UNUSED;
		}
		break;
	case PCI_PIN_ALTERNATIVE:
		/* No alternative here */
		BUG();
		pci_conf->serr_irq = PCI_PIN_UNUSED;
		break;
	}
	if (pci_conf->serr_irq != PCI_PIN_UNUSED) {
		struct resource *res =
			platform_get_resource_byname(&stx7108_pci_device,
					IORESOURCE_IRQ, "pci serr");

		BUG_ON(!res);
		res->start = pci_conf->serr_irq;
		res->end = pci_conf->serr_irq;
	}

	/* LOCK is not claimed as is totally pointless, the SOCs do not
	 * support any form of coherency */

	stx7108_pci_device.dev.parent =
		bus_find_device_by_name(&platform_bus_type, NULL, "emi");
	platform_device_register(&stx7108_pci_device);
}
Esempio n. 9
0
static int 	rk610_hdmi_i2c_probe(struct i2c_client *client,const struct i2c_device_id *id)
{
    int ret = 0;
	struct hdmi *hdmi = NULL;
	struct rk610_hdmi_inf *rk610_hdmi = NULL;

	struct hdmi_platform_data *pdata = client->dev.platform_data;
	rk610_g_hdmi_client = client;
	if(pdata && pdata->io_init)
	{
		printk("rk610_hdmi_i2c_probe io_init \n");
		pdata->io_init();
	}
	hdmi = hdmi_register(sizeof(struct rk610_hdmi_inf), &client->dev);
    if (!hdmi)
    {
        dev_err(&client->dev, "fail to register hdmi\n");
        return -ENOMEM;
    }
    	if(HDMI_SOURCE_DEFAULT == HDMI_SOURCE_LCDC0)
		hdmi->lcdc = rk_get_lcdc_drv("lcdc0");
	else
		hdmi->lcdc = rk_get_lcdc_drv("lcdc1");
	if(hdmi->lcdc == NULL)
	{
		dev_err(hdmi->dev, "can not connect to video source lcdc\n");
		ret = -ENXIO;
	}
	hdmi->ops = &rk610_hdmi_ops;
	hdmi->display_on = HDMI_DEFAULT_MODE;
	hdmi->hdcp_on = HDMI_DISABLE;
	hdmi->audio_fs = HDMI_I2S_DEFAULT_Fs;
	hdmi->resolution = HDMI_DEFAULT_RESOLUTION;
	hdmi->dual_disp = DUAL_DISP_CAP;
	hdmi->mode = DISP_ON_LCD;
	hdmi->scale = 100;
	hdmi->scale_set = 100;

	rk610_hdmi = hdmi_priv(hdmi);
	rk610_hdmi->init = 1;
	rk610_hdmi->hdmi = hdmi;
	i2c_set_clientdata(client, rk610_hdmi);
	rk610_hdmi->client = client;
	if((gpio_request(client->irq, "hdmi gpio")) < 0)
	    {
	        dev_err(&client->dev, "fail to request gpio %d\n", client->irq);
	        goto err_gpio_free;
	    }
    rk610_hdmi->irq = gpio_to_irq(client->irq);
	rk610_hdmi->gpio = client->irq;

	gpio_direction_input(client->irq);
	#if 0
	if((ret = request_irq(rk610_hdmi->irq, rk610_hdmi_interrupt, IRQ_TYPE_EDGE_RISING,client->name, hdmi))<0){
        RK610_ERR(&client->dev, "fail to request gpio %d\n", client->irq);
        goto err_gpio_free;
	}
	#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
	rk610_hdmi->early_suspend.suspend = rk610_hdmi_early_suspend;
	rk610_hdmi->early_suspend.resume = rk610_hdmi_early_resume;
	rk610_hdmi->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 1;
	register_early_suspend(&rk610_hdmi->early_suspend);
#endif
#ifdef RK610_DEBUG
	device_create_file(&(client->dev), &rk610_attrs[0]);
#endif
	rk610_hdmi_init(rk610_hdmi->hdmi);
    dev_info(&client->dev, "rk610_hdmi i2c probe ok\n");
    return 0;
err_gpio_free:
	gpio_free(client->irq);
err_hdmi_unregister:
	hdmi_unregister(hdmi);
	rk610_hdmi = NULL;
	return ret;
}
static int flounder_nct72_init(void)
{
	s32 base_cp, shft_cp;
	u32 base_ft, shft_ft;
	int nct72_port = TEGRA_GPIO_PI6;
	int ret = 0;
	int i;
	struct thermal_trip_info *trip_state;

	/* raise NCT's thresholds if soctherm CP,FT fuses are ok */
	if ((tegra_fuse_calib_base_get_cp(&base_cp, &shft_cp) >= 0) &&
	    (tegra_fuse_calib_base_get_ft(&base_ft, &shft_ft) >= 0)) {
		flounder_nct72_pdata.sensors[EXT].shutdown_limit += 20;
		for (i = 0; i < flounder_nct72_pdata.sensors[EXT].num_trips;
			 i++) {
			trip_state = &flounder_nct72_pdata.sensors[EXT].trips[i];
			if (!strncmp(trip_state->cdev_type, "cpu-balanced",
					THERMAL_NAME_LENGTH)) {
				trip_state->cdev_type = "_none_";
				break;
			}
		}
	} else {
		tegra_platform_edp_init(
			flounder_nct72_pdata.sensors[EXT].trips,
			&flounder_nct72_pdata.sensors[EXT].num_trips,
					12000); /* edp temperature margin */
		tegra_add_cpu_vmax_trips(
			flounder_nct72_pdata.sensors[EXT].trips,
			&flounder_nct72_pdata.sensors[EXT].num_trips);
		tegra_add_tgpu_trips(
			flounder_nct72_pdata.sensors[EXT].trips,
			&flounder_nct72_pdata.sensors[EXT].num_trips);
		tegra_add_vc_trips(
			flounder_nct72_pdata.sensors[EXT].trips,
			&flounder_nct72_pdata.sensors[EXT].num_trips);
		tegra_add_core_vmax_trips(
			flounder_nct72_pdata.sensors[EXT].trips,
			&flounder_nct72_pdata.sensors[EXT].num_trips);
	}

	tegra_add_all_vmin_trips(flounder_nct72_pdata.sensors[EXT].trips,
		&flounder_nct72_pdata.sensors[EXT].num_trips);

	flounder_i2c_nct72_board_info[0].irq = gpio_to_irq(nct72_port);

	ret = gpio_request(nct72_port, "temp_alert");
	if (ret < 0)
		return ret;

	ret = gpio_direction_input(nct72_port);
	if (ret < 0) {
		pr_info("%s: calling gpio_free(nct72_port)", __func__);
		gpio_free(nct72_port);
	}

	i2c_register_board_info(0, flounder_i2c_nct72_board_info,
	ARRAY_SIZE(flounder_i2c_nct72_board_info));

	return ret;
}
Esempio n. 11
0
static int __devinit omap_kp_probe(struct platform_device *pdev)
{
	struct omap_kp *omap_kp;
	struct input_dev *input_dev;
	struct omap_kp_platform_data *pdata =  pdev->dev.platform_data;
	int i, col_idx, row_idx, irq_idx, ret;

	if (!pdata->rows || !pdata->cols || !pdata->keymap) {
		return -EINVAL;
	}

	omap_kp = kzalloc(sizeof(struct omap_kp), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!omap_kp || !input_dev) {
		kfree(omap_kp);
		input_free_device(input_dev);
		return -ENOMEM;
	}

	if (cpu_is_omap44xx()) {
		//omap_kp->cclk = clk_get(NULL, "keyboard_ck");
		omap_kp->cclk = clk_get(NULL, "kbd_fck");
		if (IS_ERR(omap_kp->cclk))
		{
			goto err0;
		}
		ret = clk_enable(omap_kp->cclk);
		if (ret)
			printk(KERN_ERR "[omap_kp:] Unable to get keyboard_ck \n");
	}

	platform_set_drvdata(pdev, omap_kp);

	omap_kp->input = input_dev;

	/* Disable the interrupt for the MPUIO keyboard */
	if (!cpu_is_omap24xx() && !cpu_is_omap44xx())
		omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);

	keymap = pdata->keymap;

	if (pdata->rep)
		__set_bit(EV_REP, input_dev->evbit);

	if (pdata->delay)
		omap_kp->delay = pdata->delay;

	if (pdata->row_gpios && pdata->col_gpios) {
		row_gpios = pdata->row_gpios;
		col_gpios = pdata->col_gpios;
	}

	omap_kp->rows = pdata->rows;
	omap_kp->cols = pdata->cols;

	if (cpu_is_omap24xx()) {
		/* Cols: outputs */
		for (col_idx = 0; col_idx < omap_kp->cols; col_idx++) {
			if (gpio_request(col_gpios[col_idx], "omap_kp_col") < 0) {
				printk(KERN_ERR "[omap_kp:]Failed to request"
				       "GPIO%d for keypad\n",
				       col_gpios[col_idx]);
				goto err1;
			}
			gpio_direction_output(col_gpios[col_idx], 0);
		}
		/* Rows: inputs */
		for (row_idx = 0; row_idx < omap_kp->rows; row_idx++) {
			if (gpio_request(row_gpios[row_idx], "omap_kp_row") < 0) {
				printk(KERN_ERR "[omap_kp:]Failed to request"
				       "GPIO%d for keypad\n",
				       row_gpios[row_idx]);
				goto err2;
			}
			gpio_direction_input(row_gpios[row_idx]);
		}
	} else {
		col_idx = 0;
		row_idx = 0;
	}

	setup_timer(&omap_kp->timer, omap_kp_timer, (unsigned long)omap_kp);

	/* get the irq and init timer*/
	tasklet_enable(&kp_tasklet);
	kp_tasklet.data = (unsigned long) omap_kp;

	ret = device_create_file(&pdev->dev, &dev_attr_enable);
	if (ret < 0)
		goto err2;

#ifdef FACTORY_AT_COMMAND_GKPD
	ret = device_create_file(&pdev->dev, &dev_attr_key_test_mode);
	if (ret) {
		printk( "keypad: keypad_probe: Fail\n");
		device_remove_file(&pdev->dev, &dev_attr_key_test_mode);
	}	

	wake_lock_init(&key_wake_lock, WAKE_LOCK_SUSPEND, "omap4030_Keypad");
#endif

	/* setup input device */
	__set_bit(EV_KEY, input_dev->evbit);
	for (i = 0; keymap[i] != 0; i++)
		__set_bit(keymap[i] & KEY_MAX, input_dev->keybit);

	if (cpu_is_omap44xx())
		__set_bit(KEY_OK, input_dev->keybit);

	input_dev->name = "omap-keypad";
	input_dev->phys = "omap-keypad/input0";
	input_dev->dev.parent = &pdev->dev;

	input_dev->id.bustype = BUS_HOST;
	input_dev->id.vendor = 0x0001;
	input_dev->id.product = 0x0001;
	input_dev->id.version = 0x0100;

	ret = input_register_device(omap_kp->input);
	if (ret < 0) {
		printk(KERN_ERR "[omap_kp:]Unable to register omap-keypad input device\n");
		goto err3;
	}

	if (pdata->dbounce) {
		if (cpu_is_omap44xx())
			omap_writel(0xff, OMAP4_KBDOCP_BASE +
					OMAP4_KBD_DEBOUNCINGTIME);
		else
			omap_writew(0xff, OMAP1_MPUIO_BASE +
					OMAP_MPUIO_GPIO_DEBOUNCING);
	}

	/* scan current status and enable interrupt */
	omap_kp_scan_keypad(omap_kp, keypad_state);


	/* Configuring OMAP4 keypad registers */
	if (cpu_is_omap44xx()) {
		omap_writel(OMAP4_KBD_SYSCONFIG_SOFTRST |
			OMAP4_KBD_SYSCONFIG_ENAWKUP, OMAP4_KBDOCP_BASE
			+ OMAP4_KBD_SYSCONFIG);
		omap_writel(0x1E, OMAP4_KBDOCP_BASE + OMAP4_KBD_CTRL);
		omap_writel(0x7, OMAP4_KBDOCP_BASE + OMAP4_KBD_DEBOUNCINGTIME);
	}

	if (!cpu_is_omap24xx()) {
		omap_kp->irq = platform_get_irq(pdev, 0);
			if (request_irq(152, omap_kp_interrupt, 0,
					"omap-keypad", omap_kp) < 0)
				goto err4;
		if (!cpu_is_omap44xx())
			omap_writel(0, OMAP1_MPUIO_BASE +
					OMAP_MPUIO_KBD_MASKIT);
	} else {
		for (irq_idx = 0; irq_idx < omap_kp->rows; irq_idx++) {
			if (request_irq(gpio_to_irq(row_gpios[irq_idx]),
					omap_kp_interrupt,
					IRQF_TRIGGER_FALLING,
					"omap-keypad", omap_kp) < 0)
				goto err5;
		}
	}
	if (cpu_is_omap44xx()) {
		omap_writel(OMAP4_KBD_IRQDISABLE,
				OMAP4_KBDOCP_BASE + OMAP4_KBD_IRQSTATUS);
		omap_writel(OMAP4_KBD_IRQENABLE_EVENTEN |
				OMAP4_KBD_IRQENABLE_LONGKEY ,
				OMAP4_KBDOCP_BASE + OMAP4_KBD_IRQENABLE);
	}
	return 0;
err5:
	for (i = irq_idx - 1; i >=0; i--)
		free_irq(row_gpios[i], 0);
err4:
	input_unregister_device(omap_kp->input);
	input_dev = NULL;
err3:
	device_remove_file(&pdev->dev, &dev_attr_enable);
err2:
	for (i = row_idx - 1; i >=0; i--)
		gpio_free(row_gpios[i]);
err1:
	for (i = col_idx - 1; i >=0; i--)
		gpio_free(col_gpios[i]);
	clk_put(omap_kp->cclk);
err0:
	kfree(omap_kp);
	input_free_device(input_dev);

	return -EINVAL;
}
Esempio n. 12
0
int tdmb_fc8080_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 (fc8080_ctrl_info.spi_ptr == NULL)
	{
		printk("tdmb_fc8080_spi_write_read error txdata=0x%x, length=%d\n", (unsigned int)tx_data, tx_length+rx_length);
		return FALSE;
	}

	mutex_lock(&fc8080_ctrl_info.mutex);

	spi_message_init(&m);
	spi_message_add_tail(&t, &m);
	rc = spi_sync(fc8080_ctrl_info.spi_ptr, &m);

	if ( rc < 0 )
	{
		printk("tdmb_fc8080_spi_read_burst result(%d), actual_len=%d\n",rc, m.actual_length);
	}

	mutex_unlock(&fc8080_ctrl_info.mutex);

	return TRUE;
}

#ifdef FEATURE_DMB_USE_WORKQUEUE
static irqreturn_t broadcast_tdmb_spi_isr(int irq, void *handle)
{
	struct tdmb_fc8080_ctrl_blk* fc8080_info_p;

	fc8080_info_p = (struct tdmb_fc8080_ctrl_blk *)handle;
	if ( fc8080_info_p && fc8080_info_p->TdmbPowerOnState )
	{
		unsigned long flag;
		if (fc8080_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(&fc8080_info_p->spin_lock, flag);
		queue_work(fc8080_info_p->spi_wq, &fc8080_info_p->spi_work);
		spin_unlock_irqrestore(&fc8080_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_fc8080_ctrl_blk *pTdmbWorkData;

	pTdmbWorkData = container_of(tdmb_work, struct tdmb_fc8080_ctrl_blk, spi_work);
	if ( pTdmbWorkData )
	{
		tunerbb_drv_fc8080_isr_control(0);
		pTdmbWorkData->spi_irq_status = TRUE;
		broadcast_drv_if_isr();
		pTdmbWorkData->spi_irq_status = FALSE;
		tunerbb_drv_fc8080_isr_control(1);
	}
	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_fc8080_ctrl_blk* fc8080_info_p;

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

		tunerbb_drv_fc8080_isr_control(0);
		fc8080_info_p->spi_irq_status = TRUE;
		broadcast_drv_if_isr();
		fc8080_info_p->spi_irq_status = FALSE;
		tunerbb_drv_fc8080_isr_control(1);
	}
	else
	{
		printk("broadcast_tdmb_spi_isr is called, but device is off state\n");
	}

	return IRQ_HANDLED;
}
#endif

static int tdmb_configure_gpios(void)
{
	int rc = OK;
	int err_count = 0;

	rc = gpio_request(DMB_EN, "DMB_EN");
	if (rc < 0) {
		err_count++;
		printk("%s:Failed GPIO DMB_EN request!!!\n",__func__);
	}

	rc = gpio_request(DMB_INT_N, "DMB_INT_N");
	if (rc < 0) {
		err_count++;
		printk("%s:Failed GPIO DMB_INT_N request!!!\n",__func__);
	}

	gpio_direction_output(DMB_EN, 0);
	gpio_direction_input(DMB_INT_N);

	if(err_count > 0) rc = -EINVAL;

	return rc;
}
Esempio n. 13
0
static inline void __init apollon_init_smc91x(void)
{
	unsigned long base;

	unsigned int rate;
	struct clk *gpmc_fck;
	int eth_cs;

	gpmc_fck = clk_get(NULL, "gpmc_fck");	/* Always on ENABLE_ON_INIT */
	if (IS_ERR(gpmc_fck)) {
		WARN_ON(1);
		return;
	}

	clk_enable(gpmc_fck);
	rate = clk_get_rate(gpmc_fck);

	eth_cs = APOLLON_ETH_CS;

	/* Make sure CS1 timings are correct */
	gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);

	if (rate >= 160000000) {
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
	} else if (rate >= 130000000) {
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
	} else {/* rate = 100000000 */
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
		gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
	}

	if (gpmc_cs_request(APOLLON_ETH_CS, SZ_16M, &base) < 0) {
		printk(KERN_ERR "Failed to request GPMC CS for smc91x\n");
		goto out;
	}
	apollon_smc91x_resources[0].start = base + 0x300;
	apollon_smc91x_resources[0].end   = base + 0x30f;
	udelay(100);

	omap_mux_init_gpio(74, 0);
	if (gpio_request(APOLLON_ETHR_GPIO_IRQ, "SMC91x irq") < 0) {
		printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
			APOLLON_ETHR_GPIO_IRQ);
		gpmc_cs_free(APOLLON_ETH_CS);
		goto out;
	}
	gpio_direction_input(APOLLON_ETHR_GPIO_IRQ);

out:
	clk_disable(gpmc_fck);
	clk_put(gpmc_fck);
}
static int __devinit bfin_cf_probe(struct platform_device *pdev)
{
	struct bfin_cf_socket *cf;
	struct resource *io_mem, *attr_mem;
	int irq;
	unsigned short cd_pfx;
	int status = 0;

	dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n");

	irq = platform_get_irq(pdev, 0);
	if (irq <= 0)
		return -EINVAL;

	cd_pfx = platform_get_irq(pdev, 1);	/*Card Detect GPIO PIN */

	if (gpio_request(cd_pfx, "pcmcia: CD")) {
		dev_err(&pdev->dev,
		       "Failed ro request Card Detect GPIO_%d\n",
		       cd_pfx);
		return -EBUSY;
	}
	gpio_direction_input(cd_pfx);

	cf = kzalloc(sizeof *cf, GFP_KERNEL);
	if (!cf) {
		gpio_free(cd_pfx);
		return -ENOMEM;
	}

	cf->cd_pfx = cd_pfx;

	setup_timer(&cf->timer, bfin_cf_timer, (unsigned long)cf);

	cf->pdev = pdev;
	platform_set_drvdata(pdev, cf);

	cf->irq = irq;
	cf->socket.pci_irq = irq;

	set_irq_type(irq, IRQF_TRIGGER_LOW);

	io_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	attr_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);

	if (!io_mem || !attr_mem)
		goto fail0;

	cf->phys_cf_io = io_mem->start;
	cf->phys_cf_attr = attr_mem->start;

	/* pcmcia layer only remaps "real" memory */
	cf->socket.io_offset = (unsigned long)
	    ioremap(cf->phys_cf_io, SZ_2K);

	if (!cf->socket.io_offset)
		goto fail0;

	dev_err(&pdev->dev, ": on irq %d\n", irq);

	dev_dbg(&pdev->dev, ": %s\n",
		 bfin_cf_present(cf->cd_pfx) ? "present" : "(not present)");

	cf->socket.owner = THIS_MODULE;
	cf->socket.dev.parent = &pdev->dev;
	cf->socket.ops = &bfin_cf_ops;
	cf->socket.resource_ops = &pccard_static_ops;
	cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
	    | SS_CAP_MEM_ALIGN;
	cf->socket.map_size = SZ_2K;

	status = pcmcia_register_socket(&cf->socket);
	if (status < 0)
		goto fail2;

	cf->active = 1;
	mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
	return 0;

fail2:
	iounmap((void __iomem *)cf->socket.io_offset);
	release_mem_region(cf->phys_cf_io, SZ_8K);

fail0:
	gpio_free(cf->cd_pfx);
	kfree(cf);
	platform_set_drvdata(pdev, NULL);

	return status;
}
Esempio n. 15
0
static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	int gpio;
	enum gpio_cmd sub_cmd;
	ulong value;
	const char *str_cmd, *str_gpio;

#ifdef gpio_status
	if (argc == 2 && !strcmp(argv[1], "status")) {
		gpio_status();
		return 0;
	}
#endif

	if (argc != 3)
 show_usage:
		return CMD_RET_USAGE;
	str_cmd = argv[1];
	str_gpio = argv[2];

	/* parse the behavior */
	switch (*str_cmd) {
		case 'i': sub_cmd = GPIO_INPUT;  break;
		case 's': sub_cmd = GPIO_SET;    break;
		case 'c': sub_cmd = GPIO_CLEAR;  break;
		case 't': sub_cmd = GPIO_TOGGLE; break;
		case 'o': sub_cmd = GPIO_OSCILLATE; break;
		default:  goto show_usage;
	}

	/* turn the gpio name into a gpio number */
	gpio = name_to_gpio(str_gpio);
	if (gpio < 0)
		goto show_usage;

	/* grab the pin before we tweak it */
	if (gpio_request(gpio, "cmd_gpio")) {
		printf("gpio: requesting pin %u failed\n", gpio);
		return -1;
	}

	/* finally, let's do it: set direction and exec command */
	if (sub_cmd == GPIO_INPUT) {
		gpio_direction_input(gpio);
		value = gpio_get_value(gpio);
	} else if (sub_cmd == GPIO_OSCILLATE) {
		int i;
		gpio_direction_output(gpio, 0);
		for (i = 0; i < 100000000; i++) {
			gpio_set_value(gpio, i&1);
		}
		gpio_direction_input(gpio);
	} else {
		switch (sub_cmd) {
			case GPIO_SET:    value = 1; break;
			case GPIO_CLEAR:  value = 0; break;
			case GPIO_TOGGLE: value = !gpio_get_value(gpio); break;
			default:          goto show_usage;
		}
		gpio_direction_output(gpio, value);
	}
	printf("gpio: pin %s (gpio %i) value is %lu\n",
		str_gpio, gpio, value);

	gpio_free(gpio);

	return value;
}
Esempio n. 16
0
static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
					 struct gpio_button_data *bdata,
					 struct gpio_keys_button *button)
{
	const char *desc = button->desc ? button->desc : "gpio_keys";
	struct device *dev = &pdev->dev;
	unsigned long irqflags;
	int irq, error;

	setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
	INIT_WORK(&bdata->work, gpio_keys_work_func);

	error = gpio_request(button->gpio, desc);
	if (error < 0) {
		dev_err(dev, "failed to request GPIO %d, error %d\n",
			button->gpio, error);
		goto fail2;
	}

	error = gpio_direction_input(button->gpio);
	if (error < 0) {
		dev_err(dev, "failed to configure"
			" direction for GPIO %d, error %d\n",
			button->gpio, error);
		goto fail3;
	}

	if (button->debounce_interval) {
		error = gpio_set_debounce(button->gpio,
					  button->debounce_interval * 1000);
		/* use timer if gpiolib doesn't provide debounce */
		if (error < 0)
			bdata->timer_debounce = button->debounce_interval;
	}

	irq = gpio_to_irq(button->gpio);
	if (irq < 0) {
		error = irq;
		dev_err(dev, "Unable to get irq number for GPIO %d, error %d\n",
			button->gpio, error);
		goto fail3;
	}

	irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
	/*
	 * If platform has specified that the button can be disabled,
	 * we don't want it to share the interrupt line.
	 */
	if (!button->can_disable)
		irqflags |= IRQF_SHARED;

	if (button->wakeup)
		irqflags |= IRQF_NO_SUSPEND;

	error = request_any_context_irq(irq, gpio_keys_isr, irqflags, desc, bdata);
	if (error < 0) {
		dev_err(dev, "Unable to claim irq %d; error %d\n",
			irq, error);
		goto fail3;
	}

	return 0;

fail3:
	gpio_free(button->gpio);
fail2:
	return error;
}
Esempio n. 17
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);

	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);
	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;
}
int __init grouper_panel_init(void)
{
    int err;
    struct resource __maybe_unused *res;
    struct board_info board_info;

    tegra_get_board_info(&board_info);

#if defined(CONFIG_TEGRA_NVMAP)
    grouper_carveouts[1].base = tegra_carveout_start;
    grouper_carveouts[1].size = tegra_carveout_size;
#endif
    /*
    	gpio_request(grouper_lvds_avdd_en, "lvds_avdd_en");
    	gpio_direction_output(grouper_lvds_avdd_en, 1);
    	tegra_gpio_enable(grouper_lvds_avdd_en);

    	//gpio_request(grouper_lvds_stdby, "lvds_stdby");
    	//gpio_direction_output(grouper_lvds_stdby, 1);
    	//tegra_gpio_enable(grouper_lvds_stdby);

    	gpio_request(grouper_lvds_rst, "lvds_rst");
    	gpio_direction_output(grouper_lvds_rst, 1);
    	tegra_gpio_enable(grouper_lvds_rst);

    	if (board_info.fab == BOARD_FAB_A00) {
    		gpio_request(grouper_lvds_rs_a00, "lvds_rs");
    		gpio_direction_output(grouper_lvds_rs_a00, 0);
    		tegra_gpio_enable(grouper_lvds_rs_a00);
    	} else {
    		gpio_request(grouper_lvds_rs, "lvds_rs");
    		gpio_direction_output(grouper_lvds_rs, 0);
    		tegra_gpio_enable(grouper_lvds_rs);
    	}

    	gpio_request(grouper_lvds_lr, "lvds_lr");
    	gpio_direction_output(grouper_lvds_lr, 1);
    	tegra_gpio_enable(grouper_lvds_lr);
    */
    /*
    	gpio_request(grouper_lvds_shutdown, "lvds_shutdown");
    	gpio_direction_output(grouper_lvds_shutdown, 1);
    	tegra_gpio_enable(grouper_lvds_shutdown);
    */

    if( grouper_get_project_id() == GROUPER_PROJECT_BACH)
    {
        grouper_disp1_out.parent_clk = "pll_d_out0";
        grouper_disp1_out.modes->pclk = 81750000;
        grouper_disp1_out.modes->h_sync_width= 64;
        grouper_disp1_out.modes->h_back_porch= 128;
        grouper_disp1_out.modes->h_front_porch = 64;
        printk("Bach: Set LCD pclk as %d Hz\n", grouper_disp1_out.modes->pclk);

        gpio_request(TEGRA_GPIO_PV6, "gpio_v6");
        tegra_gpio_enable(TEGRA_GPIO_PV6);
    }

    tegra_gpio_enable(grouper_hdmi_hpd);
    gpio_request(grouper_hdmi_hpd, "hdmi_hpd");
    gpio_direction_input(grouper_hdmi_hpd);

#ifdef CONFIG_HAS_EARLYSUSPEND
    grouper_panel_early_suspender.suspend = grouper_panel_early_suspend;
    grouper_panel_early_suspender.resume = grouper_panel_late_resume;
    grouper_panel_early_suspender.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
    register_early_suspend(&grouper_panel_early_suspender);
#endif

#ifdef CONFIG_TEGRA_GRHOST
    err = nvhost_device_register(&tegra_grhost_device);
    if (err)
        return err;
#endif

    err = platform_add_devices(grouper_gfx_devices,
                               ARRAY_SIZE(grouper_gfx_devices));

#if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
    res = nvhost_get_resource_byname(&grouper_disp1_device,
                                     IORESOURCE_MEM, "fbmem");
    res->start = tegra_fb_start;
    res->end = tegra_fb_start + tegra_fb_size - 1;
#endif

    /* Copy the bootloader fb to the fb. */
//	tegra_move_framebuffer(tegra_fb_start, tegra_bootloader_fb_start,
//				min(tegra_fb_size, tegra_bootloader_fb_size));

#if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_DC)
    if (!err)
        err = nvhost_device_register(&grouper_disp1_device);

    res = nvhost_get_resource_byname(&grouper_disp2_device,
                                     IORESOURCE_MEM, "fbmem");
    res->start = tegra_fb2_start;
    res->end = tegra_fb2_start + tegra_fb2_size - 1;
    if (!err)
        err = nvhost_device_register(&grouper_disp2_device);
#endif

#if defined(CONFIG_TEGRA_GRHOST) && defined(CONFIG_TEGRA_NVAVP)
    if (!err)
        err = nvhost_device_register(&nvavp_device);
#endif
    return err;
}
static void ventana_isl29018_init(void)
{
	tegra_gpio_enable(ISL29018_IRQ_GPIO);
	gpio_request(ISL29018_IRQ_GPIO, "isl29018");
	gpio_direction_input(ISL29018_IRQ_GPIO);
}
Esempio n. 20
0
static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
{
	int err;

	tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);

	err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
		goto err_gpio_detect;
	}
	err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
	if (err)
		goto err_gpio_detect_dir;

	err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
			  IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				"MMC/SD card detect", data);
	if (err) {
		printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
		goto err_irq;
	}

	err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
		goto err_gpio_wp;
	}
	err = gpio_direction_input(TOSA_GPIO_SD_WP);
	if (err)
		goto err_gpio_wp_dir;

	err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
		goto err_gpio_pwr;
	}
	err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
	if (err)
		goto err_gpio_pwr_dir;

	err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
	if (err) {
		printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
		goto err_gpio_int;
	}
	err = gpio_direction_input(TOSA_GPIO_nSD_INT);
	if (err)
		goto err_gpio_int_dir;

	return 0;

err_gpio_int_dir:
	gpio_free(TOSA_GPIO_nSD_INT);
err_gpio_int:
err_gpio_pwr_dir:
	gpio_free(TOSA_GPIO_PWR_ON);
err_gpio_pwr:
err_gpio_wp_dir:
	gpio_free(TOSA_GPIO_SD_WP);
err_gpio_wp:
	free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
err_irq:
err_gpio_detect_dir:
	gpio_free(TOSA_GPIO_nSD_DETECT);
err_gpio_detect:
	return err;
}
static void ventana_nct1008_init(void)
{
	tegra_gpio_enable(NCT1008_THERM2_GPIO);
	gpio_request(NCT1008_THERM2_GPIO, "temp_alert");
	gpio_direction_input(NCT1008_THERM2_GPIO);
}
Esempio n. 22
0
static int __devinit sdhci_probe(struct platform_device *pdev)
{
	struct sdhci_host *host;
	struct resource *iomem;
	struct spear_sdhci *sdhci;
	int ret;

	BUG_ON(pdev == NULL);

	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!iomem) {
		ret = -ENOMEM;
		dev_dbg(&pdev->dev, "memory resource not defined\n");
		goto err;
	}

	if (!request_mem_region(iomem->start, resource_size(iomem),
				"spear-sdhci")) {
		ret = -EBUSY;
		dev_dbg(&pdev->dev, "cannot request region\n");
		goto err;
	}

	sdhci = kzalloc(sizeof(*sdhci), GFP_KERNEL);
	if (!sdhci) {
		ret = -ENOMEM;
		dev_dbg(&pdev->dev, "cannot allocate memory for sdhci\n");
		goto err_kzalloc;
	}

	/* clk enable */
	sdhci->clk = clk_get(&pdev->dev, NULL);
	if (IS_ERR(sdhci->clk)) {
		ret = PTR_ERR(sdhci->clk);
		dev_dbg(&pdev->dev, "Error getting clock\n");
		goto err_clk_get;
	}

	ret = clk_enable(sdhci->clk);
	if (ret) {
		dev_dbg(&pdev->dev, "Error enabling clock\n");
		goto err_clk_enb;
	}

	/* overwrite platform_data */
	sdhci->data = dev_get_platdata(&pdev->dev);
	pdev->dev.platform_data = sdhci;

	if (pdev->dev.parent)
		host = sdhci_alloc_host(pdev->dev.parent, 0);
	else
		host = sdhci_alloc_host(&pdev->dev, 0);

	if (IS_ERR(host)) {
		ret = PTR_ERR(host);
		dev_dbg(&pdev->dev, "error allocating host\n");
		goto err_alloc_host;
	}

	host->hw_name = "sdhci";
	host->ops = &sdhci_pltfm_ops;
	host->irq = platform_get_irq(pdev, 0);
	host->quirks = SDHCI_QUIRK_BROKEN_ADMA;

	host->ioaddr = ioremap(iomem->start, resource_size(iomem));
	if (!host->ioaddr) {
		ret = -ENOMEM;
		dev_dbg(&pdev->dev, "failed to remap registers\n");
		goto err_ioremap;
	}

	ret = sdhci_add_host(host);
	if (ret) {
		dev_dbg(&pdev->dev, "error adding host\n");
		goto err_add_host;
	}

	platform_set_drvdata(pdev, host);

	/*
	 * It is optional to use GPIOs for sdhci Power control & sdhci card
	 * interrupt detection. If sdhci->data is NULL, then use original sdhci
	 * lines otherwise GPIO lines.
	 * If GPIO is selected for power control, then power should be disabled
	 * after card removal and should be enabled when card insertion
	 * interrupt occurs
	 */
	if (!sdhci->data)
		return 0;

	if (sdhci->data->card_power_gpio >= 0) {
		int val = 0;

		ret = gpio_request(sdhci->data->card_power_gpio, "sdhci");
		if (ret < 0) {
			dev_dbg(&pdev->dev, "gpio request fail: %d\n",
					sdhci->data->card_power_gpio);
			goto err_pgpio_request;
		}

		if (sdhci->data->power_always_enb)
			val = sdhci->data->power_active_high;
		else
			val = !sdhci->data->power_active_high;

		ret = gpio_direction_output(sdhci->data->card_power_gpio, val);
		if (ret) {
			dev_dbg(&pdev->dev, "gpio set direction fail: %d\n",
					sdhci->data->card_power_gpio);
			goto err_pgpio_direction;
		}

		gpio_set_value(sdhci->data->card_power_gpio, 1);
	}

	if (sdhci->data->card_int_gpio >= 0) {
		ret = gpio_request(sdhci->data->card_int_gpio, "sdhci");
		if (ret < 0) {
			dev_dbg(&pdev->dev, "gpio request fail: %d\n",
					sdhci->data->card_int_gpio);
			goto err_igpio_request;
		}

		ret = gpio_direction_input(sdhci->data->card_int_gpio);
		if (ret) {
			dev_dbg(&pdev->dev, "gpio set direction fail: %d\n",
					sdhci->data->card_int_gpio);
			goto err_igpio_direction;
		}
		ret = request_irq(gpio_to_irq(sdhci->data->card_int_gpio),
				sdhci_gpio_irq, IRQF_TRIGGER_LOW,
				mmc_hostname(host->mmc), pdev);
		if (ret) {
			dev_dbg(&pdev->dev, "gpio request irq fail: %d\n",
					sdhci->data->card_int_gpio);
			goto err_igpio_request_irq;
		}

	}

	return 0;

err_igpio_request_irq:
err_igpio_direction:
	if (sdhci->data->card_int_gpio >= 0)
		gpio_free(sdhci->data->card_int_gpio);
err_igpio_request:
err_pgpio_direction:
	if (sdhci->data->card_power_gpio >= 0)
		gpio_free(sdhci->data->card_power_gpio);
err_pgpio_request:
	platform_set_drvdata(pdev, NULL);
	sdhci_remove_host(host, 1);
err_add_host:
	iounmap(host->ioaddr);
err_ioremap:
	sdhci_free_host(host);
err_alloc_host:
	clk_disable(sdhci->clk);
err_clk_enb:
	clk_put(sdhci->clk);
err_clk_get:
	kfree(sdhci);
err_kzalloc:
	release_mem_region(iomem->start, resource_size(iomem));
err:
	dev_err(&pdev->dev, "spear-sdhci probe failed: %d\n", ret);
	return ret;
}
Esempio n. 23
0
static __init void da850_evm_init(void)
{
	int ret;

	ret = da850_register_gpio();
	if (ret)
		pr_warn("%s: GPIO init failed: %d\n", __func__, ret);

	ret = pmic_tps65070_init();
	if (ret)
		pr_warn("%s: TPS65070 PMIC init failed: %d\n", __func__, ret);

	ret = da850_register_edma(da850_edma_rsv);
	if (ret)
		pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);

	ret = davinci_cfg_reg_list(da850_i2c0_pins);
	if (ret)
		pr_warn("%s: I2C0 mux setup failed: %d\n", __func__, ret);

	ret = da8xx_register_i2c(0, &da850_evm_i2c_0_pdata);
	if (ret)
		pr_warn("%s: I2C0 registration failed: %d\n", __func__, ret);


	ret = da8xx_register_watchdog();
	if (ret)
		pr_warn("%s: watchdog registration failed: %d\n",
			__func__, ret);

	if (HAS_MMC) {
		ret = davinci_cfg_reg_list(da850_evm_mmcsd0_pins);
		if (ret)
			pr_warn("%s: MMCSD0 mux setup failed: %d\n",
				__func__, ret);

		ret = gpio_request(DA850_MMCSD_CD_PIN, "MMC CD\n");
		if (ret)
			pr_warn("%s: can not open GPIO %d\n",
				__func__, DA850_MMCSD_CD_PIN);
		gpio_direction_input(DA850_MMCSD_CD_PIN);

		ret = gpio_request(DA850_MMCSD_WP_PIN, "MMC WP\n");
		if (ret)
			pr_warn("%s: can not open GPIO %d\n",
				__func__, DA850_MMCSD_WP_PIN);
		gpio_direction_input(DA850_MMCSD_WP_PIN);

		ret = da8xx_register_mmcsd0(&da850_mmc_config);
		if (ret)
			pr_warn("%s: MMCSD0 registration failed: %d\n",
				__func__, ret);

		ret = da850_wl12xx_init();
		if (ret)
			pr_warn("%s: WL12xx initialization failed: %d\n",
				__func__, ret);
	}

	davinci_serial_init(da8xx_serial_device);

	i2c_register_board_info(1, da850_evm_i2c_devices,
			ARRAY_SIZE(da850_evm_i2c_devices));

	/*
	 * shut down uart 0 and 1; they are not used on the board and
	 * accessing them causes endless "too much work in irq53" messages
	 * with arago fs
	 */
	__raw_writel(0, IO_ADDRESS(DA8XX_UART1_BASE) + 0x30);
	__raw_writel(0, IO_ADDRESS(DA8XX_UART0_BASE) + 0x30);

	ret = davinci_cfg_reg_list(da850_evm_mcasp_pins);
	if (ret)
		pr_warn("%s: McASP mux setup failed: %d\n", __func__, ret);

	da850_evm_snd_data.sram_pool = sram_get_gen_pool();
	da8xx_register_mcasp(0, &da850_evm_snd_data);

	ret = davinci_cfg_reg_list(da850_lcdcntl_pins);
	if (ret)
		pr_warn("%s: LCDC mux setup failed: %d\n", __func__, ret);

	ret = da8xx_register_uio_pruss();
	if (ret)
		pr_warn("da850_evm_init: pruss initialization failed: %d\n",
				ret);

	/* Handle board specific muxing for LCD here */
	ret = davinci_cfg_reg_list(da850_evm_lcdc_pins);
	if (ret)
		pr_warn("%s: EVM specific LCD mux setup failed: %d\n",
			__func__, ret);

	ret = da850_lcd_hw_init();
	if (ret)
		pr_warn("%s: LCD initialization failed: %d\n", __func__, ret);

	sharp_lk043t1dg01_pdata.panel_power_ctrl = da850_panel_power_ctrl,
	ret = da8xx_register_lcdc(&sharp_lk043t1dg01_pdata);
	if (ret)
		pr_warn("%s: LCDC registration failed: %d\n", __func__, ret);

	ret = da8xx_register_rtc();
	if (ret)
		pr_warn("%s: RTC setup failed: %d\n", __func__, ret);

	ret = da850_evm_init_cpufreq();
	if (ret)
		pr_warn("%s: cpufreq registration failed: %d\n", __func__, ret);

	ret = da8xx_register_cpuidle();
	if (ret)
		pr_warn("%s: cpuidle registration failed: %d\n", __func__, ret);

	ret = da850_register_pm(&da850_pm_device);
	if (ret)
		pr_warn("%s: suspend registration failed: %d\n", __func__, ret);

	da850_vpif_init();

	ret = spi_register_board_info(da850evm_spi_info,
				      ARRAY_SIZE(da850evm_spi_info));
	if (ret)
		pr_warn("%s: spi info registration failed: %d\n", __func__,
			ret);

	ret = da8xx_register_spi_bus(1, ARRAY_SIZE(da850evm_spi_info));
	if (ret)
		pr_warn("%s: SPI 1 registration failed: %d\n", __func__, ret);

	ret = da850_register_sata(DA850EVM_SATA_REFCLKPN_RATE);
	if (ret)
		pr_warn("%s: SATA registration failed: %d\n", __func__, ret);

	da850_evm_setup_mac_addr();

	ret = da8xx_register_rproc();
	if (ret)
		pr_warn("%s: dsp/rproc registration failed: %d\n",
			__func__, ret);
}
int __init rpi_power_switch_init(void)
{
	int ret = 0;

	old_pm_power_off = pm_power_off;
	pm_power_off = rpi_power_switch_power_off;

	pr_info("Adafruit Industries' power switch driver v%s\n",
		RPI_POWER_SWITCH_VERSION);

	INIT_DELAYED_WORK(&initiate_shutdown_work, initiate_shutdown);


	/* Register our own class for the power switch */
	ret = class_register(&power_switch_class);
        if (ret < 0) {
		pr_err("%s: Unable to register class\n", power_switch_class.name);
		goto out0;     
	}


        /* Create devices for each PWM present */
	switch_dev = device_create(&power_switch_class, &platform_bus,
                                MKDEV(0, 0), NULL, "pswitch%u", 0);
	if (IS_ERR(switch_dev)) {
		pr_err("%s: device_create failed\n", power_switch_class.name);
		ret = PTR_ERR(switch_dev);
		goto out1;
        }

	ret = sysfs_create_group(&switch_dev->kobj,
				 &rpi_power_switch_attribute_group);
	if (ret < 0) {
		pr_err("%s: create_group failed\n", power_switch_class.name);
		goto out2;
	}

	/* GPIO register memory must be mapped before doing any direct
	 * accesses such as changing GPIO alt functions or changing GPIO
	 * pull ups or pull downs.
	 */
	gpio_reg = ioremap(GPIO_BASE, 1024);

	/* Set the specified pin as a GPIO input */
	SET_GPIO_INPUT(gpio_pin);

	/* Set the pin as a pulldown.  Most pins should default to having
	 * pulldowns, and this seems most intuitive.
	 */
	set_gpio_pull(gpio_pin, GPIO_PULL_UP);

	gpio_request(gpio_pin, "Power switch");
	gpio_direction_input(gpio_pin);

	/* The targeted polarity should be the opposite of the current value.
	 * I.e. we want the pin to transition to this state in order to
	 * initiate a shutdown.
	 */
	gpio_pol = !gpio_get_value(gpio_pin);

	/* Request an interrupt to fire when the pin transitions to our
	 * desired state.
	 */
	ret = request_irq(__gpio_to_irq(gpio_pin), power_isr,
			  gpio_pol?IRQF_TRIGGER_RISING:IRQF_TRIGGER_FALLING,
			  "Power button", NULL);
	if (ret) {
		pr_err("Unable to request IRQ\n");
		goto out3;
	}

	return 0;


	/* Error handling */
out3:
	sysfs_remove_group(&switch_dev->kobj,&rpi_power_switch_attribute_group);
out2:
	device_unregister(switch_dev);
out1:
	class_unregister(&power_switch_class);
out0:
	iounmap(gpio_reg);
	pm_power_off = old_pm_power_off;
	return ret;
}
static int __devinit sharpsl_pm_probe(struct platform_device *pdev)
{
	int ret;

	if (!pdev->dev.platform_data)
		return -EINVAL;

	sharpsl_pm.dev = &pdev->dev;
	sharpsl_pm.machinfo = pdev->dev.platform_data;
	sharpsl_pm.charge_mode = CHRG_OFF;
	sharpsl_pm.flags = 0;

	init_timer(&sharpsl_pm.ac_timer);
	sharpsl_pm.ac_timer.function = sharpsl_ac_timer;

	init_timer(&sharpsl_pm.chrg_full_timer);
	sharpsl_pm.chrg_full_timer.function = sharpsl_chrg_full_timer;

	led_trigger_register_simple("sharpsl-charge", &sharpsl_charge_led_trigger);

	sharpsl_pm.machinfo->init();

	gpio_request(sharpsl_pm.machinfo->gpio_acin, "AC IN");
	gpio_direction_input(sharpsl_pm.machinfo->gpio_acin);
	gpio_request(sharpsl_pm.machinfo->gpio_batfull, "Battery Full");
	gpio_direction_input(sharpsl_pm.machinfo->gpio_batfull);
	gpio_request(sharpsl_pm.machinfo->gpio_batlock, "Battery Lock");
	gpio_direction_input(sharpsl_pm.machinfo->gpio_batlock);

	/* Register interrupt handlers */
	if (request_irq(PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_acin), sharpsl_ac_isr, IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "AC Input Detect", sharpsl_ac_isr)) {
		dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_acin));
	}

	if (request_irq(PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_batlock), sharpsl_fatal_isr, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "Battery Cover", sharpsl_fatal_isr)) {
		dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_batlock));
	}

	if (sharpsl_pm.machinfo->gpio_fatal) {
		if (request_irq(PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_fatal), sharpsl_fatal_isr, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "Fatal Battery", sharpsl_fatal_isr)) {
			dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_fatal));
		}
	}

	if (sharpsl_pm.machinfo->batfull_irq) {
		/* Register interrupt handler. */
		if (request_irq(PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_batfull), sharpsl_chrg_full_isr, IRQF_DISABLED | IRQF_TRIGGER_RISING, "CO", sharpsl_chrg_full_isr)) {
			dev_err(sharpsl_pm.dev, "Could not get irq %d.\n", PXA_GPIO_TO_IRQ(sharpsl_pm.machinfo->gpio_batfull));
		}
	}

	ret = device_create_file(&pdev->dev, &dev_attr_battery_percentage);
	ret |= device_create_file(&pdev->dev, &dev_attr_battery_voltage);
	if (ret != 0)
		dev_warn(&pdev->dev, "Failed to register attributes (%d)\n", ret);

	apm_get_power_status = sharpsl_apm_get_power_status;

#ifdef CONFIG_PM
	suspend_set_ops(&sharpsl_pm_ops);
#endif

	mod_timer(&sharpsl_pm.ac_timer, jiffies + msecs_to_jiffies(250));

	return 0;
}
Esempio n. 26
0
static int __devinit omap2_onenand_probe(struct platform_device *pdev)
{
	struct omap_onenand_platform_data *pdata;
	struct omap2_onenand *c;
	int r;

	pdata = pdev->dev.platform_data;
	if (pdata == NULL) {
		dev_err(&pdev->dev, "platform data missing\n");
		return -ENODEV;
	}

	c = kzalloc(sizeof(struct omap2_onenand), GFP_KERNEL);
	if (!c)
		return -ENOMEM;

	init_completion(&c->irq_done);
	init_completion(&c->dma_done);
	c->gpmc_cs = pdata->cs;
	c->gpio_irq = pdata->gpio_irq;
	c->dma_channel = pdata->dma_channel;
	if (c->dma_channel < 0) {
		/* if -1, don't use DMA */
		c->gpio_irq = 0;
	}

	r = gpmc_cs_request(c->gpmc_cs, ONENAND_IO_SIZE, &c->phys_base);
	if (r < 0) {
		dev_err(&pdev->dev, "Cannot request GPMC CS\n");
		goto err_kfree;
	}

	if (request_mem_region(c->phys_base, ONENAND_IO_SIZE,
			       pdev->dev.driver->name) == NULL) {
		dev_err(&pdev->dev, "Cannot reserve memory region at 0x%08lx, "
			"size: 0x%x\n",	c->phys_base, ONENAND_IO_SIZE);
		r = -EBUSY;
		goto err_free_cs;
	}
	c->onenand.base = ioremap(c->phys_base, ONENAND_IO_SIZE);
	if (c->onenand.base == NULL) {
		r = -ENOMEM;
		goto err_release_mem_region;
	}

	if (pdata->onenand_setup != NULL) {
		r = pdata->onenand_setup(c->onenand.base, c->freq);
		if (r < 0) {
			dev_err(&pdev->dev, "Onenand platform setup failed: "
				"%d\n", r);
			goto err_iounmap;
		}
		c->setup = pdata->onenand_setup;
	}

	if (c->gpio_irq) {
		if ((r = gpio_request(c->gpio_irq, "OneNAND irq")) < 0) {
			dev_err(&pdev->dev,  "Failed to request GPIO%d for "
				"OneNAND\n", c->gpio_irq);
			goto err_iounmap;
	}
	gpio_direction_input(c->gpio_irq);

	if ((r = request_irq(gpio_to_irq(c->gpio_irq),
			     omap2_onenand_interrupt, IRQF_TRIGGER_RISING,
			     pdev->dev.driver->name, c)) < 0)
		goto err_release_gpio;
	}

	if (c->dma_channel >= 0) {
		r = omap_request_dma(0, pdev->dev.driver->name,
				     omap2_onenand_dma_cb, (void *) c,
				     &c->dma_channel);
		if (r == 0) {
			omap_set_dma_write_mode(c->dma_channel,
						OMAP_DMA_WRITE_NON_POSTED);
			omap_set_dma_src_data_pack(c->dma_channel, 1);
			omap_set_dma_src_burst_mode(c->dma_channel,
						    OMAP_DMA_DATA_BURST_8);
			omap_set_dma_dest_data_pack(c->dma_channel, 1);
			omap_set_dma_dest_burst_mode(c->dma_channel,
						     OMAP_DMA_DATA_BURST_8);
		} else {
			dev_info(&pdev->dev,
				 "failed to allocate DMA for OneNAND, "
				 "using PIO instead\n");
			c->dma_channel = -1;
		}
	}

	dev_info(&pdev->dev, "initializing on CS%d, phys base 0x%08lx, virtual "
		 "base %p\n", c->gpmc_cs, c->phys_base,
		 c->onenand.base);

	c->pdev = pdev;
	c->mtd.name = pdev->dev.bus_id;
	c->mtd.priv = &c->onenand;
	c->mtd.owner = THIS_MODULE;

	if (c->dma_channel >= 0) {
		struct onenand_chip *this = &c->onenand;

		this->wait = omap2_onenand_wait;
		if (cpu_is_omap34xx()) {
			this->read_bufferram = omap3_onenand_read_bufferram;
			this->write_bufferram = omap3_onenand_write_bufferram;
		} else {
			this->read_bufferram = omap2_onenand_read_bufferram;
			this->write_bufferram = omap2_onenand_write_bufferram;
		}
	}

	if ((r = onenand_scan(&c->mtd, 1)) < 0)
		goto err_release_dma;

	switch ((c->onenand.version_id >> 4) & 0xf) {
	case 0:
		c->freq = 40;
		break;
	case 1:
		c->freq = 54;
		break;
	case 2:
		c->freq = 66;
		break;
	case 3:
		c->freq = 83;
		break;
	}

#ifdef CONFIG_MTD_PARTITIONS
	if (pdata->parts != NULL)
		r = add_mtd_partitions(&c->mtd, pdata->parts,
				       pdata->nr_parts);
	else
#endif
		r = add_mtd_device(&c->mtd);
	if (r < 0)
		goto err_release_onenand;

	platform_set_drvdata(pdev, c);

	return 0;

err_release_onenand:
	onenand_release(&c->mtd);
err_release_dma:
	if (c->dma_channel != -1)
		omap_free_dma(c->dma_channel);
	if (c->gpio_irq)
		free_irq(gpio_to_irq(c->gpio_irq), c);
err_release_gpio:
	if (c->gpio_irq)
		gpio_free(c->gpio_irq);
err_iounmap:
	iounmap(c->onenand.base);
err_release_mem_region:
	release_mem_region(c->phys_base, ONENAND_IO_SIZE);
err_free_cs:
	gpmc_cs_free(c->gpmc_cs);
err_kfree:
	kfree(c);

	return r;
}
Esempio n. 27
0
static int get_pins_from_dts(void) {

	pinctrl = devm_pinctrl_get(&vdev_dev->client->dev);

	pin_in[0] = pinctrl_lookup_state(pinctrl, "gpio0_in");
	pin_in[1] = pinctrl_lookup_state(pinctrl, "gpio1_in");
	pin_in[2] = pinctrl_lookup_state(pinctrl, "gpio2_in");
	pin_in[3] = pinctrl_lookup_state(pinctrl, "gpio3_in");
	pin_in[4] = pinctrl_lookup_state(pinctrl, "gpio4_in");
	pin_in[5] = pinctrl_lookup_state(pinctrl, "gpio5_in");
	pin_in[6] = pinctrl_lookup_state(pinctrl, "gpio6_in");
	pin_in[7] = pinctrl_lookup_state(pinctrl, "gpio7_in");
	pin_in[8] = pinctrl_lookup_state(pinctrl, "gpio8_in");
	pin_in[9] = pinctrl_lookup_state(pinctrl, "gpio9_in");
	pin_out[0] = pinctrl_lookup_state(pinctrl, "gpio0_out");
	pin_out[1] = pinctrl_lookup_state(pinctrl, "gpio1_out");
	pin_out[2] = pinctrl_lookup_state(pinctrl, "gpio2_out");
	pin_out[3] = pinctrl_lookup_state(pinctrl, "gpio3_out");
	pin_out[4] = pinctrl_lookup_state(pinctrl, "gpio4_out");
	pin_out[5] = pinctrl_lookup_state(pinctrl, "gpio5_out");
	pin_out[6] = pinctrl_lookup_state(pinctrl, "gpio6_out");
	pin_out[7] = pinctrl_lookup_state(pinctrl, "gpio7_out");
	pin_out[8] = pinctrl_lookup_state(pinctrl, "gpio8_out");
	pin_out[9] = pinctrl_lookup_state(pinctrl, "gpio9_out");
	pin_irq1 = pinctrl_lookup_state(pinctrl, "irq1");
	pin_irq2 = pinctrl_lookup_state(pinctrl, "irq2");
	pin_irq3 = pinctrl_lookup_state(pinctrl, "irq3");
  
    pin[0] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio0", 0, NULL);
    pin[1] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio1", 0, NULL);
    pin[2] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio2", 0, NULL);
    pin[3] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio3", 0, NULL);
    pin[4] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio4", 0, NULL);
    pin[5] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio5", 0, NULL);
    pin[6] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio6", 0, NULL);
    pin[7] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio7", 0, NULL);
    pin[8] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio8", 0, NULL);
    pin[9] = of_get_named_gpio_flags(vdev_dev->client->dev.of_node, "intel,gpio9", 0, NULL);

    if(gpio_request(pin[0],"pin0") != 0) {
	  printk("vdev: pin0 request error\n");
	}
    if(gpio_request(pin[1],"pin1") != 0) {
	  printk("vdev: pin1 request error\n");
	}
    if(gpio_request(pin[2],"pin2") != 0) {
	  printk("vdev: pin2 request error\n");
	}
    if(gpio_request(pin[3],"pin3") != 0) {
	  printk("vdev: pin3 request error\n");
	}
    if(gpio_request(pin[4],"pin4") != 0) {
	  printk("vdev: pin4 request error\n");
	}
    if(gpio_request(pin[5],"pin5") != 0) {
	  printk("vdev: pin5 request error\n");
	}
    if(gpio_request(pin[6],"pin6") != 0) {
	  printk("vdev: pin6 request error\n");
	}
    if(gpio_request(pin[7],"pin7") != 0) {
	  printk("vdev: pin7 request error\n");
	}
    if(gpio_request(pin[8],"pin8") != 0) {
	  printk("vdev: pin8 request error\n");
	}
    if(gpio_request(pin[9],"pin9") != 0) {
	  printk("vdev: pin9 request error\n");
	}
	gpio_direction_input(pin[0]);
	gpio_direction_input(pin[1]);
	gpio_direction_input(pin[2]);
	gpio_direction_input(pin[3]);
	gpio_direction_input(pin[4]);
	gpio_direction_input(pin[5]);
	gpio_direction_input(pin[6]);
	gpio_direction_input(pin[7]);
	gpio_direction_input(pin[8]);
	gpio_direction_input(pin[9]);

    return 0;

}
Esempio n. 28
0
static int __devinit mipi_orise_lcd_probe(struct platform_device *pdev)
{
	struct msm_fb_data_type *mfd;
	struct mipi_panel_info *mipi;
	struct platform_device *current_pdev;
	static struct mipi_dsi_phy_ctrl *phy_settings;
	int rc = 0;
	
	if (pdev->id == 0) {
		mipi_orise_pdata = pdev->dev.platform_data;

		if (mipi_orise_pdata
			&& mipi_orise_pdata->phy_ctrl_settings) {
			phy_settings = (mipi_orise_pdata->phy_ctrl_settings);
		}
		return 0;
	}

	current_pdev = msm_fb_add_device(pdev);

	if (current_pdev) {
		mfd = platform_get_drvdata(current_pdev);
		if (!mfd)
			return -ENODEV;
		if (mfd->key != MFD_KEY)
			return -EINVAL;

		mipi  = &mfd->panel_info.mipi;

		if (phy_settings != NULL)
			mipi->dsi_phy_db = phy_settings;
	}

	rc = gpio_request(LCD_TE_GPIO, "LCD_TE_GPIO#");
	if (rc < 0) {
		pr_err("MIPI GPIO LCD_TE_GPIO request failed: %d\n", rc);
		return -ENODEV;
	}
	rc = gpio_direction_input(LCD_TE_GPIO);
	if (rc < 0) {
		pr_err("MIPI GPIO LCD_TE_GPIO set failed: %d\n", rc);
		return -ENODEV;
	}

	irq = gpio_to_irq(LCD_TE_GPIO);

	rc = request_threaded_irq(irq, NULL, TE_irq_thread_fn,
				 IRQF_TRIGGER_RISING, "LCD_TE",NULL);
	if (rc < 0) {
		pr_err("Unable to register IRQ handler\n");
		return -ENODEV;
	}

	INIT_DELAYED_WORK(&techeck_work, techeck_work_func );
	schedule_delayed_work(&techeck_work, msecs_to_jiffies(20000));
	init_suspend();

	/* ATTR node: [email protected]:/sys/devices/virtual/graphics/fb0/orise_bkl */
	mfd = platform_get_drvdata(current_pdev);
	rc = sysfs_create_group(&mfd->fbi->dev->kobj, &fs_attr_bkl_ctrl);
	if (rc) {
		pr_err("%s: fs_attr_bkl_ctrl sysfs group creation failed, rc=%d\n", __func__, rc);
		return rc;
	}

/* OPPO 2013-03-07 zhengzk Add begin for reason */
	display_switch.name = "dispswitch";

	rc = switch_dev_register(&display_switch);
	if (rc) {
		pr_err("Unable to register display switch device\n");
		return rc;
	}
/* OPPO 2013-03-07 zhengzk Add end */

	return 0;
}
Esempio n. 29
0
static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
					 struct input_dev *input,
					 struct gpio_button_data *bdata,
					 const struct gpio_keys_button *button)
{
	const char *desc = button->desc ? button->desc : "gpio_keys";
	struct device *dev = &pdev->dev;
	irq_handler_t isr;
	unsigned long irqflags;
	int irq, error;

	bdata->input = input;
	bdata->button = button;
	spin_lock_init(&bdata->lock);

	if (gpio_is_valid(button->gpio)) {

		error = gpio_request(button->gpio, desc);
		if (error < 0) {
			dev_err(dev, "Failed to request GPIO %d, error %d\n",
				button->gpio, error);
			return error;
		}

		error = gpio_direction_input(button->gpio);
		if (error < 0) {
			dev_err(dev,
				"Failed to configure direction for GPIO %d, error %d\n",
				button->gpio, error);
			goto fail;
		}

		if (button->debounce_interval) {
			error = gpio_set_debounce(button->gpio,
					button->debounce_interval * 1000);
			/* use timer if gpiolib doesn't provide debounce */
			if (error < 0)
				bdata->timer_debounce =
						button->debounce_interval;
		}

		irq = gpio_to_irq(button->gpio);
		if (irq < 0) {
			error = irq;
			dev_err(dev,
				"Unable to get irq number for GPIO %d, error %d\n",
				button->gpio, error);
			goto fail;
		}
		bdata->irq = irq;

		INIT_WORK(&bdata->work, gpio_keys_gpio_work_func);
		setup_timer(&bdata->timer,
			    gpio_keys_gpio_timer, (unsigned long)bdata);

		isr = gpio_keys_gpio_isr;
		irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;

	} else {
		if (!button->irq) {
			dev_err(dev, "No IRQ specified\n");
			return -EINVAL;
		}
		bdata->irq = button->irq;

		if (button->type && button->type != EV_KEY) {
			dev_err(dev, "Only EV_KEY allowed for IRQ buttons.\n");
			return -EINVAL;
		}

		bdata->timer_debounce = button->debounce_interval;
		setup_timer(&bdata->timer,
			    gpio_keys_irq_timer, (unsigned long)bdata);

		isr = gpio_keys_irq_isr;
		irqflags = 0;
	}

	input_set_capability(input, button->type ?: EV_KEY, button->code);

	/*
	 * If platform has specified that the button can be disabled,
	 * we don't want it to share the interrupt line.
	 */
	if (!button->can_disable)
		irqflags |= IRQF_SHARED;

	error = request_any_context_irq(bdata->irq, isr, irqflags, desc, bdata);
	if (error < 0) {
		dev_err(dev, "Unable to claim irq %d; error %d\n",
			bdata->irq, error);
		goto fail;
	}

	return 0;

fail:
	if (gpio_is_valid(button->gpio))
		gpio_free(button->gpio);

	return error;
}
Esempio n. 30
0
static int es8323_probe(struct snd_soc_codec *codec)
{
	// struct es8323_priv *es8323 = snd_soc_codec_get_drvdata(codec);
	struct snd_soc_dapm_context *dapm = &codec->dapm;
	int ret = 0;
	unsigned long flags=0;
	// u16 reg,i;

    printk("%s\n", __func__);
#if 0
    ret = gpio_request(RK30_PIN0_PC7, NULL);
    if (ret != 0) {
        printk("%s request RK30_PIN0_PC7 error", __func__);
        return ret;
    }
    gpio_direction_input(RK30_PIN0_PC7);
#endif
#if 0
    ret = gpio_request(SPK_CON, NULL);
    if (ret != 0) {
            printk("%s request SPK_CON error", __func__);
            return ret;
    }
    //gpio_set_value(SPK_CON, 1);
    gpio_direction_output(SPK_CON,0);


		ret = gpio_request(HP_DET, NULL);
		if (ret != 0) {
				printk("%s request HP_DET error", __func__);
				return ret;
		}
		gpio_direction_input(HP_DET);
		
		flags = gpio_get_value(HP_DET) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
		
		HP_IRQ = gpio_to_irq(HP_DET);
    if (HP_IRQ){
        ret = request_irq(HP_IRQ, hp_det_irq_handler, flags, "ES8323", NULL);
        if(ret == 0){
            printk("%s:register ISR (irq=%d)\n", __FUNCTION__,HP_IRQ);
        }
        else 
			printk("request_irq HP_IRQ failed\n");
    }
	
#endif
gpio_set_value(SPK_CON,0);
	if (codec == NULL) {
		dev_err(codec->dev, "Codec device not registered\n");
		return -ENODEV;
	}
    codec->read  = es8323_read_reg_cache;
    codec->write = es8323_write;
    codec->hw_write = (hw_write_t)i2c_master_send;
	codec->control_data = container_of(codec->dev, struct i2c_client, dev);

	es8323_codec = codec;
	ret = es8323_reset(codec);
	if (ret < 0) {
		dev_err(codec->dev, "Failed to issue reset\n");
		return ret;
	}
	#if (RT5633_SPK_TIMER == 1)
	setup_timer( &spk_timer, spk_timer_callback, 0 );
	ret = mod_timer( &spk_timer, jiffies + msecs_to_jiffies(5000) );
	if (ret)
		printk("Error in mod_timer\n");
	INIT_WORK(&spk_work, spk_work_handler);
	es8323_ANVOL=1;
#endif
	
  //es8323_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  
#if 1	
    //snd_soc_write(codec, 0x35  , 0xa0); 
    //snd_soc_write(codec, 0x36  , 0x08); //for 1.8V VDD
snd_soc_write(codec, 0x02,0xf3);
snd_soc_write(codec, 0x2B,0x80);
snd_soc_write(codec, 0x08,0x00);   //ES8388 salve  
snd_soc_write(codec, 0x00,0x32);   //
snd_soc_write(codec, 0x01,0x72);   //PLAYBACK & RECORD Mode,EnRefr=1
snd_soc_write(codec, 0x03,0x59);   //pdn_ana=0,ibiasgen_pdn=0
snd_soc_write(codec, 0x05,0x00);   //pdn_ana=0,ibiasgen_pdn=0
snd_soc_write(codec, 0x06,0xc3);   //pdn_ana=0,ibiasgen_pdn=0 
snd_soc_write(codec, 0x09,0x88);  //ADC L/R PGA =  +24dB
//----------------------------------------------------------------------------------------------------------------
snd_soc_write(codec, 0x0a,0xf0);  //ADC INPUT=LIN2/RIN2
snd_soc_write(codec, 0x0b,0x82);  //ADC INPUT=LIN2/RIN2 //82
//-----------------------------------------------------------------------------------------------------------------
snd_soc_write(codec, 0x0C,0x4c);  //I2S-24BIT
snd_soc_write(codec, 0x0d,0x02);  //MCLK/LRCK=256 
snd_soc_write(codec, 0x10,0x00);  //ADC Left Volume=0db
snd_soc_write(codec, 0x11,0x00);  //ADC Right Volume=0db
snd_soc_write(codec, 0x12,0xea); // ALC stereo MAXGAIN: 35.5dB,  MINGAIN: +6dB (Record Volume increased!)
snd_soc_write(codec, 0x13,0x60);
snd_soc_write(codec, 0x14,0x05);
snd_soc_write(codec, 0x15,0x06);
snd_soc_write(codec, 0x16,0x53);  
snd_soc_write(codec, 0x17,0x18);  //I2S-16BIT
snd_soc_write(codec, 0x18,0x02);
//snd_soc_write(codec, 0x1A,0x00);  //DAC VOLUME=0DB
//snd_soc_write(codec, 0x1B,0x00);

snd_soc_write(codec, 0x1A,0x0a);  //DAC VOLUME=-11.5DB 3.1v
snd_soc_write(codec, 0x1B,0x0a);
//snd_soc_write(codec, 0x1A,0x0e);  //DAC VOLUME=-7.5DB 3v ?????????IJ???
//snd_soc_write(codec, 0x1B,0x0e);
                /*
                snd_soc_write(codec, 0x1E,0x01);    //for 47uF capacitors ,15db [email protected],Fs=44100
                snd_soc_write(codec, 0x1F,0x84);
                snd_soc_write(codec, 0x20,0xED);
                snd_soc_write(codec, 0x21,0xAF);
                snd_soc_write(codec, 0x22,0x20);
                snd_soc_write(codec, 0x23,0x6C);
                snd_soc_write(codec, 0x24,0xE9);
                snd_soc_write(codec, 0x25,0xBE);
                */
snd_soc_write(codec, 0x26,0x12);  //Left DAC TO Left IXER
snd_soc_write(codec, 0x27,0xb8);  //Left DAC TO Left MIXER
snd_soc_write(codec, 0x28,0x38);
snd_soc_write(codec, 0x29,0x38);
snd_soc_write(codec, 0x2A,0xb8);
snd_soc_write(codec, 0x02,0x00); //aa //START DLL and state-machine,START DSM 
snd_soc_write(codec, 0x19,0x02);  //SOFT RAMP RATE=32LRCKS/STEP,Enable ZERO-CROSS CHECK,DAC MUTE
snd_soc_write(codec, 0x04,0x0c);   //pdn_ana=0,ibiasgen_pdn=0  
msleep(100);
snd_soc_write(codec, 0x2e,0x00); 
snd_soc_write(codec, 0x2f,0x00);
snd_soc_write(codec, 0x30,0x08); 
snd_soc_write(codec, 0x31,0x08);
msleep(200);
snd_soc_write(codec, 0x30,0x0f); 
snd_soc_write(codec, 0x31,0x0f);
msleep(200);
snd_soc_write(codec, 0x30,0x18); 
snd_soc_write(codec, 0x31,0x18);
msleep(100);
snd_soc_write(codec, 0x04,0x2c);   //pdn_ana=0,ibiasgen_pdn=0 
#endif	
	
  //s8323_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  //codec->dapm.bias_level = SND_SOC_BIAS_STANDBY;
      
	snd_soc_add_controls(codec, es8323_snd_controls,
				ARRAY_SIZE(es8323_snd_controls));
	snd_soc_dapm_new_controls(dapm, es8323_dapm_widgets,
				  ARRAY_SIZE(es8323_dapm_widgets));
	snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
	  
	//create_proc_read_entry("es8323_suspend", 0644, NULL, entry_read, NULL);

	mdelay(10);
	#if 1
    ret = gpio_request(SPK_CON, NULL);
    if (ret != 0) {
            printk("%s request SPK_CON error", __func__);
            return ret;
    }
    //gpio_set_value(SPK_CON, 1);
    gpio_direction_output(SPK_CON,0);


		ret = gpio_request(HP_DET, NULL);
		if (ret != 0) {
				printk("%s request HP_DET error", __func__);
				return ret;
		}
		gpio_direction_input(HP_DET);
		
		flags = gpio_get_value(HP_DET) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
		
		HP_IRQ = gpio_to_irq(HP_DET);
    if (HP_IRQ){
        ret = request_irq(HP_IRQ, hp_det_irq_handler, flags, "ES8323", NULL);
        if(ret == 0){
            printk("%s:register ISR (irq=%d)\n", __FUNCTION__,HP_IRQ);
        }
        else 
			printk("request_irq HP_IRQ failed\n");
    }

	if(0 == gpio_get_value(HP_DET)){
		printk("probe,hp_det = 0,insert hp\n");
		gpio_set_value(SPK_CON,0);
	}else if(1 == gpio_get_value(HP_DET)){
		printk("probe,hp_det = 1,deinsert hp\n");
		gpio_set_value(SPK_CON,1);
	}
#endif
	return 0;
}