Exemplo n.º 1
0
static int of_tsu6721_muic_dt(struct device *dev,
			struct tsu6721_muic_data *muic_data)
{
	struct device_node *np_muic = dev->of_node;
	int ret = 0;

	if (np_muic == NULL) {
		pr_err("%s np NULL\n", __func__);
		return -EINVAL;
	} else {
		muic_data->pdata->irq_gpio = of_get_named_gpio(np_muic,
							"muic,muic_int", 0);
		if (muic_data->pdata->irq_gpio < 0) {
			pr_err("%s error reading muic_irq = %d\n", __func__,
						muic_data->pdata->irq_gpio);
			muic_data->pdata->irq_gpio = 0;
		}
		if (of_gpio_count(np_muic) < 1) {
			dev_err(muic_data->dev, "could not find muic gpio\n");
			muic_data->pdata->gpio_uart_sel = 0;
		} else {
			muic_data->pdata->gpio_uart_sel =
					of_get_gpio(np_muic, 0);
		}
	}

	return ret;
}
static int parse_dsi_drvdata(struct device_node *np)
{
	u32 temp, i;

	DT_READ_U32_OPTIONAL(np, "e_interface", g_dsim_config.e_interface);
	DT_READ_U32_OPTIONAL(np, "e_pixel_format",
		g_dsim_config.e_pixel_format);
	DT_READ_U32_OPTIONAL(np, "auto_flush", g_dsim_config.auto_flush);
	DT_READ_U32_OPTIONAL(np, "eot_disable", g_dsim_config.eot_disable);
	DT_READ_U32_OPTIONAL(np, "auto_vertical_cnt",
		g_dsim_config.auto_vertical_cnt);
	DT_READ_U32_OPTIONAL(np, "hse", g_dsim_config.hse);
	DT_READ_U32_OPTIONAL(np, "hfp", g_dsim_config.hfp);
	DT_READ_U32_OPTIONAL(np, "hbp", g_dsim_config.hbp);
	DT_READ_U32_OPTIONAL(np, "hsa", g_dsim_config.hsa);
	DT_READ_U32_OPTIONAL(np, "e_no_data_lane",
		g_dsim_config.e_no_data_lane);
	DT_READ_U32_OPTIONAL(np, "e_byte_clk", g_dsim_config.e_byte_clk);
	DT_READ_U32_OPTIONAL(np, "e_burst_mode", g_dsim_config.e_burst_mode);
	DT_READ_U32_OPTIONAL(np, "p", g_dsim_config.p);
	DT_READ_U32_OPTIONAL(np, "m", g_dsim_config.m);
	DT_READ_U32_OPTIONAL(np, "s", g_dsim_config.s);
	DT_READ_U32_OPTIONAL(np, "pll_stable_time",
		g_dsim_config.pll_stable_time);
	DT_READ_U32_OPTIONAL(np, "esc_clk", g_dsim_config.esc_clk);
	DT_READ_U32_OPTIONAL(np, "stop_holding_cnt",
		g_dsim_config.stop_holding_cnt);
	DT_READ_U32_OPTIONAL(np, "bta_timeout", g_dsim_config.bta_timeout);
	DT_READ_U32_OPTIONAL(np, "rx_timeout", g_dsim_config.rx_timeout);

	for (i = 0; i < of_gpio_count(np); i++)
		g_disp_gpios.id[i] = of_get_gpio(np, i);

	return 0;
}
Exemplo n.º 3
0
static int tiny_spi_of_probe(struct platform_device *pdev)
{
	struct tiny_spi *hw = platform_get_drvdata(pdev);
	struct device_node *np = pdev->dev.of_node;
	unsigned int i;
	const __be32 *val;
	int len;

	if (!np)
		return 0;
	hw->gpio_cs_count = of_gpio_count(np);
	if (hw->gpio_cs_count > 0) {
		hw->gpio_cs = devm_kzalloc(&pdev->dev,
				hw->gpio_cs_count * sizeof(unsigned int),
				GFP_KERNEL);
		if (!hw->gpio_cs)
			return -ENOMEM;
	}
	for (i = 0; i < hw->gpio_cs_count; i++) {
		hw->gpio_cs[i] = of_get_gpio_flags(np, i, NULL);
		if (hw->gpio_cs[i] < 0)
			return -ENODEV;
	}
	hw->bitbang.master->dev.of_node = pdev->dev.of_node;
	val = of_get_property(pdev->dev.of_node,
			      "clock-frequency", &len);
	if (val && len >= sizeof(__be32))
		hw->freq = be32_to_cpup(val);
	val = of_get_property(pdev->dev.of_node, "baud-width", &len);
	if (val && len >= sizeof(__be32))
		hw->baudwidth = be32_to_cpup(val);
	return 0;
}
Exemplo n.º 4
0
static int nokia_modem_gpio_probe(struct device *dev)
{
	struct device_node *np = dev->of_node;
	struct nokia_modem_device *modem = dev_get_drvdata(dev);
	int gpio_count, gpio_name_count, i, err;

	gpio_count = of_gpio_count(np);

	if (gpio_count < 0) {
		dev_err(dev, "missing gpios: %d\n", gpio_count);
		return gpio_count;
	}

	gpio_name_count = of_property_count_strings(np, "gpio-names");

	if (gpio_count != gpio_name_count) {
		dev_err(dev, "number of gpios does not equal number of gpio names\n");
		return -EINVAL;
	}

	modem->gpios = devm_kzalloc(dev, gpio_count *
				sizeof(struct nokia_modem_gpio), GFP_KERNEL);
	if (!modem->gpios) {
		dev_err(dev, "Could not allocate memory for gpios\n");
		return -ENOMEM;
	}

	modem->gpio_amount = gpio_count;

	for (i = 0; i < gpio_count; i++) {
		modem->gpios[i].gpio = devm_gpiod_get_index(dev, NULL, i);
		if (IS_ERR(modem->gpios[i].gpio)) {
			dev_err(dev, "Could not get gpio %d\n", i);
			return PTR_ERR(modem->gpios[i].gpio);
		}

		err = of_property_read_string_index(np, "gpio-names", i,
						&(modem->gpios[i].name));
		if (err) {
			dev_err(dev, "Could not get gpio name %d\n", i);
			return err;
		}

		err = gpiod_direction_output(modem->gpios[i].gpio, 0);
		if (err)
			return err;

		err = gpiod_export(modem->gpios[i].gpio, 0);
		if (err)
			return err;

		err = gpiod_export_link(dev, modem->gpios[i].name,
							modem->gpios[i].gpio);
		if (err)
			return err;
	}

	return 0;
}
Exemplo n.º 5
0
static struct mmi_factory_info *mmi_parse_of(struct platform_device *pdev)
{
	struct mmi_factory_info *info;
	int gpio_count;
	struct device_node *np = pdev->dev.of_node;
	int i;
	enum of_gpio_flags flags;

	if (!np) {
		dev_err(&pdev->dev, "No OF DT node found.\n");
		return NULL;
	}

	gpio_count = of_gpio_count(np);

	if (!gpio_count) {
		dev_err(&pdev->dev, "No GPIOS defined.\n");
		return NULL;
	}

	/* Make sure number of GPIOs defined matches the supplied number of
	 * GPIO name strings.
	 */
	if (gpio_count != of_property_count_strings(np, "gpio-names")) {
		dev_err(&pdev->dev, "GPIO info and name mismatch\n");
		return NULL;
	}

	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
	if (!info)
		return NULL;

	info->list = devm_kzalloc(&pdev->dev,
				sizeof(struct gpio) * gpio_count,
				GFP_KERNEL);
	if (!info->list)
		return NULL;

	info->num_gpios = gpio_count;
	for (i = 0; i < gpio_count; i++) {
		info->list[i].gpio = of_get_gpio_flags(np, i, &flags);
		info->list[i].flags = flags;
		of_property_read_string_index(np, "gpio-names", i,
						&info->list[i].label);
		dev_dbg(&pdev->dev, "GPIO: %d  FLAGS: %ld  LABEL: %s\n",
			info->list[i].gpio, info->list[i].flags,
			info->list[i].label);
	}

	return info;
}
Exemplo n.º 6
0
static int32_t msm_ois_get_gpio_data(struct msm_ois_ctrl_t *a_ctrl,
	struct device_node *of_node)
{
	int32_t rc = 0;
	uint32_t i = 0;
	uint16_t gpio_array_size = 0;
	uint16_t *gpio_array = NULL;

	CDBG_I("Enter\n");

	a_ctrl->gpio_conf = kzalloc(sizeof(struct msm_camera_gpio_conf),
		GFP_KERNEL);
	if (!a_ctrl->gpio_conf) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}
	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size) {
		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
			GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto ERROR1;
		}
		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			CDBG("%s gpio_array[%d] = %d\n", __func__, i,
				gpio_array[i]);
		}

		rc = msm_ois_get_dt_gpio_req_tbl(of_node,
			a_ctrl->gpio_conf, gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR2;
		}
		kfree(gpio_array);
	}
	return 0;

ERROR2:
	kfree(gpio_array);
ERROR1:
	kfree(a_ctrl->gpio_conf);
	return rc;
}
/*
 * Check whether usb3 is available by checking hw_id.
 */
bool msm_is_usb3_available(void)
{
	struct device_node *node;
	int gpio_count;
	int hw_id;
	int i;

	node = of_find_node_by_name(of_find_node_by_path("/"), "gpio_hw_ids");
	if (!node) {
		pr_err("hw_id: node \"gpio_hw_ids\" does not exist.");
		return false;
	}

	gpio_count = of_gpio_count(node);
	if (!gpio_count) {
		pr_err("hw_id: GPIO is not assigned.");
		return false;
	}

	hw_id = 0;
	for (i = 0; i < gpio_count; i++) {
		int gpio;
		int ret;

		gpio = of_get_gpio(node, i);
		if (!gpio_is_valid(gpio)) {
			pr_err("hw_id: Failed to get gpio hw_id_%d.", i);
			return false;
		}

		ret = gpio_request(gpio, NULL);
		if (ret) {
			pr_err("hw_id: Failed to request gpio hw_id_%d.", i);
			return false;
		}

		ret = gpio_get_value(gpio);
		gpio_free(gpio);
		hw_id |= ret << i;
	}

	pr_info("usb3.0 is %savailable. hw_id=0x%02x",
						hw_id ? "" : "NOT ", hw_id);

	/* If hw_id is 0, usb3 is not available. */
	return hw_id ? true : false;
}
static int of_ioboard_keyled_get_pins       (struct device_node *np)
{
    int cnt, gpio_cnt;
    
	if ((gpio_cnt = of_gpio_count(np)) < IOBOARD_MAX)   {
		pr_err("Invalid GPIO pins. count = %d\n", gpio_cnt);
		return -ENODEV;
	}

    for(cnt = 0; cnt < gpio_cnt; cnt++) {
        sControlGpios[cnt].gpio = of_get_gpio(np, cnt);
        if(!gpio_is_valid(sControlGpios[cnt].gpio)) {
    		pr_err("%s: invalid GPIO pins, gpio.name=%s/gpio_no=%d\n",
    		       np->full_name, sControlGpios[cnt].name, sControlGpios[cnt].gpio);
    		return -ENODEV;
        }
    }

	return 0;
}
Exemplo n.º 9
0
static int __init of_gpio_export_probe(struct platform_device *pdev)
{
	struct device_node *np = pdev->dev.of_node;
	struct device_node *cnp;
	u32 val;
	int nb = 0;

	for_each_child_of_node(np, cnp) {
		const char *name = NULL;
		int gpio;
		bool dmc;
		int max_gpio = 1;
		int i;

		of_property_read_string(cnp, "gpio-export,name", &name);

		if (!name)
			max_gpio = of_gpio_count(cnp);

		for (i = 0; i < max_gpio; i++) {
			gpio = of_get_gpio(cnp, i);
			if (devm_gpio_request(&pdev->dev, gpio, name ? name : of_node_full_name(np)))
				continue;

			if (!of_property_read_u32(cnp, "gpio-export,output", &val))
				gpio_direction_output(gpio, val);
			else
				gpio_direction_input(gpio);

			dmc = of_property_read_bool(np, "gpio-export,direction_may_change");
			gpio_export_with_name(gpio, dmc, name);
			nb++;
		}
	}

	dev_info(&pdev->dev, "%d gpio(s) exported\n", nb);

	return 0;
}
Exemplo n.º 10
0
static int c55_ctrl_gpio_setup(struct c55_ctrl_data *cdata, struct device *dev)
{
	int i;

	if (of_gpio_count(dev->of_node) != NUM_GPIOS) {
		dev_err(dev, "%s: gpio count is not %d.\n", __func__, NUM_GPIOS);
		return -EINVAL;
	}

	for (i = 0; i < NUM_GPIOS; i++) {
		enum of_gpio_flags flags;
		int gpio;

		gpio = of_get_gpio_flags(dev->of_node, i, &flags);
		if (gpio < 0) {
			pr_err("%s: of_get_gpio failed: %d\n", __func__, gpio);
			return gpio;
		}

		gpio_request(gpio, gpio_labels[i]);

		gpio_export(gpio, false);
		gpio_export_link(dev, gpio_labels[i], gpio);

		if ((flags & GPIOF_IN) == GPIOF_IN) {
			gpio_direction_input(gpio);
			c55_ctrl_int_setup(cdata, gpio);
		} else {
			cdata->ap_c55_int_gpio = gpio;
			if ((flags & GPIOF_OUT_INIT_HIGH) == GPIOF_OUT_INIT_HIGH)
				gpio_direction_output(gpio, 1);
			else
				gpio_direction_output(gpio, 0);
		}
	}

	return 0;
}
static int32_t msm_led_trigger_get_dt_data(struct device_node *of_node, struct msm_led_flash_ctrl_t *fctrl)
{
	struct msm_flash_gpio_conf_t *gconf = NULL;
	uint16_t *gpio_array = NULL;
	uint16_t gpio_array_size = 0;
	uint32_t id_info[3] = {0};
	int32_t rc = 0, i = 0;

	rc = of_property_read_u32(of_node, "cell-index", &fctrl->pdev->id);
	CDBG("%s: pdev id %d\n", __func__, fctrl->pdev->id);
	if (rc < 0) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
		return -EINVAL;
	}

	rc = of_property_read_u32(of_node, "qcom,cci-master",	&fctrl->cci_i2c_master);
	CDBG("%s: qcom,cci-master %d, rc %d\n", __func__, fctrl->cci_i2c_master, rc);
	if (rc < 0) {
		fctrl->cci_i2c_master = MASTER_0;
		rc = 0;
	}

	rc = msm_led_trigger_get_dt_vreg_data(of_node, &fctrl->board_info);
	if (rc < 0) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
	}

	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s: gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size) {

		fctrl->board_info.gpio_conf = kzalloc(sizeof(struct msm_flash_gpio_conf_t), GFP_KERNEL);
		if (!fctrl->board_info.gpio_conf) {
			pr_err("%s: failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto msm_led_trigger_get_dt_data_failed;
		}
		gconf = fctrl->board_info.gpio_conf;
	
		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size, GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s: failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto msm_led_trigger_get_dt_data_failed;
		}

		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			CDBG("%s: gpio_array[%d] = %d\n", __func__, i, gpio_array[i]);
		}

		rc = msm_led_trigger_get_dt_gpio_req_tbl(of_node, gconf, gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s: failed %d\n", __func__, __LINE__);
			goto msm_led_trigger_get_dt_data_failed;
		}

		rc = msm_led_trigger_init_gpio_pin_tbl(of_node, gconf, gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s: failed %d\n", __func__, __LINE__);
			goto msm_led_trigger_get_dt_data_failed;
		}
	}

	fctrl->board_info.slave_info = kzalloc(sizeof(struct msm_flash_slave_info_t),	GFP_KERNEL);
	if (!fctrl->board_info.slave_info) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
		rc = -ENOMEM;
		goto msm_led_trigger_get_dt_data_failed;
	}

	rc = of_property_read_u32_array(of_node, "qcom,slave-id",	id_info, 3);
	if (rc < 0) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
		goto msm_led_trigger_get_dt_data_failed;
	}

	fctrl->board_info.slave_info->flash_slave_addr = id_info[0];
	fctrl->board_info.slave_info->flash_id_reg_addr = id_info[1];
	fctrl->board_info.slave_info->flash_id = id_info[2];

	rc = of_property_read_string(of_node, "qcom,flash-name", &fctrl->board_info.flash_name);
	if (rc < 0) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
		goto msm_led_trigger_get_dt_data_failed;
	}

	rc = msm_led_trigger_get_slave_device_i2c_reg_info(of_node, fctrl->reg_setting);
	if (rc < 0) {
		pr_err("%s: failed %d\n", __func__, __LINE__);
	}

	kfree(gpio_array);

	return 0;

msm_led_trigger_get_dt_data_failed:

	if (fctrl->board_info.slave_info) {
		kfree(fctrl->board_info.slave_info);
		fctrl->board_info.slave_info = NULL;
	}

	if (fctrl->board_info.gpio_conf->gpio_num_info) {
		kfree(fctrl->board_info.gpio_conf->gpio_num_info);
		fctrl->board_info.gpio_conf->gpio_num_info = NULL;
	}

	if (fctrl->board_info.gpio_conf->flash_gpio_req_tbl) {
		kfree(fctrl->board_info.gpio_conf->flash_gpio_req_tbl);
		fctrl->board_info.gpio_conf->flash_gpio_req_tbl = NULL;
	}

	if (gpio_array) {
		kfree(gpio_array);
	}

	if (fctrl->board_info.gpio_conf) {
		kfree(fctrl->board_info.gpio_conf);
		fctrl->board_info.gpio_conf = NULL;
	}

	if (fctrl->board_info.vreg_conf) {
		kfree(fctrl->board_info.vreg_conf);
		fctrl->board_info.vreg_conf = NULL;
	}

	return rc;
}
Exemplo n.º 12
0
static struct stml0xx_platform_data *stml0xx_of_init(struct spi_device *spi)
{
	int len;
	int lsize, bsize, index;
	struct stml0xx_platform_data *pdata;
	struct device_node *np = spi->dev.of_node;
	unsigned int lux_table[LIGHTING_TABLE_SIZE];
	unsigned int brightness_table[LIGHTING_TABLE_SIZE];
	const char *name;

	pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata) {
		dev_err(&stml0xx_misc_data->spi->dev,
			"pdata allocation failure");
		return NULL;
	}

	pdata->gpio_int = of_get_gpio(np, 0);
	pdata->gpio_reset = of_get_gpio(np, 1);
	pdata->gpio_bslen = of_get_gpio(np, 2);
	pdata->gpio_wakeirq = of_get_gpio(np, 3);

	if (of_gpio_count(np) >= 6) {
		pdata->gpio_spi_ready_for_receive = of_get_gpio(np, 4);
		pdata->gpio_spi_data_ack = of_get_gpio(np, 5);
	} else {
		dev_err(&stml0xx_misc_data->spi->dev,
			"spi side band signals not defined");
		return NULL;
	}

	if (of_gpio_count(np) >= 7) {
		pdata->gpio_sh_wake = of_get_gpio(np, 6);
		stml0xx_misc_data->sh_lowpower_enabled = 1;
	} else {
		pdata->gpio_sh_wake = -1;
		stml0xx_misc_data->sh_lowpower_enabled = 0;
	}

	if (of_get_property(np, "lux_table", &len) == NULL) {
		dev_err(&stml0xx_misc_data->spi->dev,
			"lux_table len access failure");
		return NULL;
	}
	lsize = len / sizeof(u32);
	if ((lsize != 0) && (lsize < (LIGHTING_TABLE_SIZE - 1)) &&
	    (!of_property_read_u32_array(np, "lux_table",
					 (u32 *) (lux_table), lsize))) {
		for (index = 0; index < lsize; index++)
			pdata->lux_table[index] = ((u32 *) lux_table)[index];
	} else {
		dev_err(&stml0xx_misc_data->spi->dev,
			"Lux table is missing");
		return NULL;
	}
	pdata->lux_table[lsize] = 0xFFFF;

	if (of_get_property(np, "brightness_table", &len) == NULL) {
		dev_err(&stml0xx_misc_data->spi->dev,
			"Brightness_table len access failure");
		return NULL;
	}
	bsize = len / sizeof(u32);
	if ((bsize != 0) && (bsize < (LIGHTING_TABLE_SIZE)) &&
	    !of_property_read_u32_array(np,
					"brightness_table",
					(u32 *) (brightness_table), bsize)) {

		for (index = 0; index < bsize; index++) {
			pdata->brightness_table[index]
			    = ((u32 *) brightness_table)[index];
		}
	} else {
		dev_err(&stml0xx_misc_data->spi->dev,
			"Brightness table is missing");
		return NULL;
	}

	if ((lsize + 1) != bsize) {
		dev_err(&stml0xx_misc_data->spi->dev,
			"Lux and Brightness table sizes don't match");
		return NULL;
	}

	of_property_read_u32(np, "bslen_pin_active_value",
			     &pdata->bslen_pin_active_value);

	pdata->reset_hw_type = 0;
	of_property_read_u32(np, "reset_hw_type",
		&pdata->reset_hw_type);

	of_get_property(np, "stml0xx_fw_version", &len);
	if (!of_property_read_string(np, "stml0xx_fw_version", &name))
		strlcpy(pdata->fw_version, name, FW_VERSION_SIZE);
	else
		dev_dbg(&stml0xx_misc_data->spi->dev,
			"Not using stml0xx_fw_version override");

	pdata->ct406_detect_threshold = 0x00C8;
	pdata->ct406_undetect_threshold = 0x00A5;
	pdata->ct406_recalibrate_threshold = 0x0064;
	pdata->ct406_pulse_count = 0x02;
	pdata->ct406_prox_gain = 0x02;
	of_property_read_u32(np, "ct406_detect_threshold",
			     &pdata->ct406_detect_threshold);
	of_property_read_u32(np, "ct406_undetect_threshold",
			     &pdata->ct406_undetect_threshold);
	of_property_read_u32(np, "ct406_recalibrate_threshold",
			     &pdata->ct406_recalibrate_threshold);
	of_property_read_u32(np, "ct406_pulse_count",
			     &pdata->ct406_pulse_count);
	of_property_read_u32(np, "ct406_prox_gain",
			     &pdata->ct406_prox_gain);
	pdata->ct406_als_lux1_c0_mult = 0x294;
	pdata->ct406_als_lux1_c1_mult = 0x55A;
	pdata->ct406_als_lux1_div = 0x64;
	pdata->ct406_als_lux2_c0_mult = 0xDA;
	pdata->ct406_als_lux2_c1_mult = 0x186;
	pdata->ct406_als_lux2_div = 0x64;
	of_property_read_u32(np, "ct406_als_lux1_c0_mult",
			     &pdata->ct406_als_lux1_c0_mult);
	of_property_read_u32(np, "ct406_als_lux1_c1_mult",
			     &pdata->ct406_als_lux1_c1_mult);
	of_property_read_u32(np, "ct406_als_lux1_div",
			     &pdata->ct406_als_lux1_div);
	of_property_read_u32(np, "ct406_als_lux2_c0_mult",
			     &pdata->ct406_als_lux2_c0_mult);
	of_property_read_u32(np, "ct406_als_lux2_c1_mult",
			     &pdata->ct406_als_lux2_c1_mult);
	of_property_read_u32(np, "ct406_als_lux2_div",
			     &pdata->ct406_als_lux2_div);

	pdata->dsp_iface_enable = 0;
	of_property_read_u32(np, "dsp_iface_enable",
				&pdata->dsp_iface_enable);

	pdata->headset_detect_enable = 0;
	pdata->headset_hw_version = 0;
	pdata->headset_insertion_debounce = 0x01F4;
	pdata->headset_removal_debounce = 0x01F4;
	pdata->headset_button_down_debounce = 0x0032;
	pdata->headset_button_up_debounce = 0x0032;
	pdata->headset_button_0_1_threshold = 0x0096;
	pdata->headset_button_1_2_threshold = 0x012C;
	pdata->headset_button_2_3_threshold = 0x01C2;
	pdata->headset_button_3_upper_threshold = 0x02EE;
	pdata->headset_button_1_keycode = 0xE2;
	pdata->headset_button_2_keycode = 0x0;
	pdata->headset_button_3_keycode = 0x0;
	pdata->headset_button_4_keycode = 0x0;
	of_property_read_u32(np, "headset_detect_enable",
			     &pdata->headset_detect_enable);
	of_property_read_u32(np, "headset_hw_version",
			     &pdata->headset_hw_version);
	of_property_read_u32(np, "headset_insertion_debounce",
			     &pdata->headset_insertion_debounce);
	of_property_read_u32(np, "headset_removal_debounce",
			     &pdata->headset_removal_debounce);
	of_property_read_u32(np, "headset_button_down_debounce",
			     &pdata->headset_button_down_debounce);
	of_property_read_u32(np, "headset_button_up_debounce",
			     &pdata->headset_button_up_debounce);
	of_property_read_u32(np, "headset_button_0-1_threshold",
			     &pdata->headset_button_0_1_threshold);
	of_property_read_u32(np, "headset_button_1-2_threshold",
			     &pdata->headset_button_1_2_threshold);
	of_property_read_u32(np, "headset_button_2-3_threshold",
			     &pdata->headset_button_2_3_threshold);
	of_property_read_u32(np, "headset_button_3-upper_threshold",
			     &pdata->headset_button_3_upper_threshold);
	of_property_read_u32(np, "headset_button_1_keycode",
			     &pdata->headset_button_1_keycode);
	of_property_read_u32(np, "headset_button_2_keycode",
			     &pdata->headset_button_2_keycode);
	of_property_read_u32(np, "headset_button_3_keycode",
			     &pdata->headset_button_3_keycode);
	of_property_read_u32(np, "headset_button_4_keycode",
			     &pdata->headset_button_4_keycode);

	pdata->cover_detect_polarity = 0;
	of_property_read_u32(np, "cover_detect_polarity",
			     &pdata->cover_detect_polarity);

	pdata->accel_orientation_1 = 0;
	pdata->accel_orientation_2 = 0;
	of_property_read_u32(np, "accel_orientation_1",
			     &pdata->accel_orientation_1);
	of_property_read_u32(np, "accel_orientation_2",
			     &pdata->accel_orientation_2);

	pdata->accel_swap = 0;
	of_property_read_u32(np, "accel_swap",
			     &pdata->accel_swap);

	return pdata;
}
Exemplo n.º 13
0
static int32_t msm_flash_get_gpio_dt_data(struct device_node *of_node,
		struct msm_flash_ctrl_t *fctrl)
{
	int32_t rc = 0, i = 0;
	uint16_t *gpio_array = NULL;
	int16_t gpio_array_size = 0;
	struct msm_camera_gpio_conf *gconf = NULL;

	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size > 0) {
		fctrl->power_info.gpio_conf =
			 kzalloc(sizeof(struct msm_camera_gpio_conf),
				 GFP_KERNEL);
		if (!fctrl->power_info.gpio_conf) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			return rc;
		}
		gconf = fctrl->power_info.gpio_conf;

		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
			GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto free_gpio_conf;
		}
		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			if (((int16_t)gpio_array[i]) < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				return -EINVAL;
			}
			CDBG("%s gpio_array[%d] = %d\n", __func__, i,
				gpio_array[i]);
		}

		rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto free_gpio_array;
		}

		rc = msm_camera_get_dt_gpio_set_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto free_cam_gpio_req_tbl;
		}

		rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto free_cam_gpio_set_tbl;
		}
		if (fctrl->flash_driver_type == FLASH_DRIVER_DEFAULT)
			fctrl->flash_driver_type = FLASH_DRIVER_GPIO;
		CDBG("%s:%d fctrl->flash_driver_type = %d", __func__, __LINE__,
			fctrl->flash_driver_type);
	}

	return 0;

free_cam_gpio_set_tbl:
	kfree(gconf->cam_gpio_set_tbl);
free_cam_gpio_req_tbl:
	kfree(gconf->cam_gpio_req_tbl);
free_gpio_array:
	kfree(gpio_array);
free_gpio_conf:
	kfree(fctrl->power_info.gpio_conf);
	return rc;
}
Exemplo n.º 14
0
static int msm_eeprom_get_dt_data(struct msm_eeprom_ctrl_t *e_ctrl)
{
	int rc = 0, i = 0;
	struct msm_eeprom_board_info *eb_info;
	struct msm_camera_power_ctrl_t *power_info =
		&e_ctrl->eboard_info->power_info;
	struct device_node *of_node = NULL;
	struct msm_camera_gpio_conf *gconf = NULL;
	uint16_t gpio_array_size = 0;
	uint16_t *gpio_array = NULL;

	eb_info = e_ctrl->eboard_info;
	if (e_ctrl->eeprom_device_type == MSM_CAMERA_SPI_DEVICE)
		of_node = e_ctrl->i2c_client.
			spi_client->spi_master->dev.of_node;
	else if (e_ctrl->eeprom_device_type == MSM_CAMERA_PLATFORM_DEVICE)
		of_node = e_ctrl->pdev->dev.of_node;
	else if (e_ctrl->eeprom_device_type == MSM_CAMERA_I2C_DEVICE)
		of_node = e_ctrl->i2c_client.client->dev.of_node;

	rc = msm_camera_get_dt_vreg_data(of_node, &power_info->cam_vreg,
					     &power_info->num_vreg);
	if (rc < 0)
		return rc;

	rc = msm_camera_get_dt_power_setting_data(of_node,
		power_info->cam_vreg, power_info->num_vreg,
		&power_info->power_setting, &power_info->power_setting_size);
	if (rc < 0)
		goto error1;

	power_info->gpio_conf = kzalloc(sizeof(struct msm_camera_gpio_conf),
					GFP_KERNEL);
	if (!power_info->gpio_conf) {
		rc = -ENOMEM;
		goto error2;
	}
	gconf = power_info->gpio_conf;
	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size) {
		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
			GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto error3;
		}
		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			CDBG("%s gpio_array[%d] = %d\n", __func__, i,
				gpio_array[i]);
		}

		rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto error4;
		}

		rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto error4;
		}
		kfree(gpio_array);
	}

	return rc;
error4:
	kfree(gpio_array);
error3:
	kfree(power_info->gpio_conf);
error2:
	kfree(power_info->cam_vreg);
error1:
	kfree(power_info->power_setting);
	return rc;
}
static int32_t msm_led_get_dt_data(struct device_node *of_node,
                                   struct msm_led_flash_ctrl_t *fctrl)
{
    int32_t rc = 0, i = 0;
    struct msm_camera_gpio_conf *gconf = NULL;
    struct device_node *flash_src_node = NULL;
    struct msm_camera_sensor_board_info *flashdata = NULL;
    struct msm_camera_power_ctrl_t *power_info = NULL;
    uint32_t count = 0;
    uint16_t *gpio_array = NULL;
    uint16_t gpio_array_size = 0;
    uint32_t id_info[3];

    CDBG("called\n");

    if (!of_node) {
        pr_err("of_node NULL\n");
        return -EINVAL;
    }

    fctrl->flashdata = kzalloc(sizeof(
                                   struct msm_camera_sensor_board_info),
                               GFP_KERNEL);
    if (!fctrl->flashdata) {
        pr_err("%s failed %d\n", __func__, __LINE__);
        return -ENOMEM;
    }

    flashdata = fctrl->flashdata;
    power_info = &flashdata->power_info;

    rc = of_property_read_u32(of_node, "cell-index", &fctrl->subdev_id);
    if (rc < 0) {
        pr_err("failed\n");
        return -EINVAL;
    }

    CDBG("subdev id %d\n", fctrl->subdev_id);

    rc = of_property_read_string(of_node, "label",
                                 &flashdata->sensor_name);
    CDBG("%s label %s, rc %d\n", __func__,
         flashdata->sensor_name, rc);
    if (rc < 0) {
        pr_err("%s failed %d\n", __func__, __LINE__);
        goto ERROR1;
    }

    rc = of_property_read_u32(of_node, "qcom,cci-master",
                              &fctrl->cci_i2c_master);
    CDBG("%s qcom,cci-master %d, rc %d\n", __func__, fctrl->cci_i2c_master,
         rc);
    if (rc < 0) {
        /* Set default master 0 */
        fctrl->cci_i2c_master = MASTER_0;
        rc = 0;
    }

    fctrl->pinctrl_info.use_pinctrl = false;
    fctrl->pinctrl_info.use_pinctrl = of_property_read_bool(of_node,
                                      "qcom,enable_pinctrl");
    if (of_get_property(of_node, "qcom,flash-source", &count)) {
        count /= sizeof(uint32_t);
        CDBG("count %d\n", count);
        if (count > MAX_LED_TRIGGERS) {
            pr_err("failed\n");
            return -EINVAL;
        }
        for (i = 0; i < count; i++) {
            flash_src_node = of_parse_phandle(of_node,
                                              "qcom,flash-source", i);
            if (!flash_src_node) {
                pr_err("flash_src_node NULL\n");
                continue;
            }

            rc = of_property_read_string(flash_src_node,
                                         "linux,default-trigger",
                                         &fctrl->flash_trigger_name[i]);
            if (rc < 0) {
                pr_err("failed\n");
                of_node_put(flash_src_node);
                continue;
            }

            CDBG("default trigger %s\n",
                 fctrl->flash_trigger_name[i]);

            rc = of_property_read_u32(flash_src_node,
                                      "qcom,max-current",
                                      &fctrl->flash_op_current[i]);
            if (rc < 0) {
                pr_err("failed rc %d\n", rc);
                of_node_put(flash_src_node);
                continue;
            }

            of_node_put(flash_src_node);

            CDBG("max_current[%d] %d\n",
                 i, fctrl->flash_op_current[i]);

            led_trigger_register_simple(
                fctrl->flash_trigger_name[i],
                &fctrl->flash_trigger[i]);
        }

    } else { /*Handle LED Flash Ctrl by GPIO*/
        power_info->gpio_conf =
            kzalloc(sizeof(struct msm_camera_gpio_conf),
                    GFP_KERNEL);
        if (!power_info->gpio_conf) {
            pr_err("%s failed %d\n", __func__, __LINE__);
            rc = -ENOMEM;
            return rc;
        }
        gconf = power_info->gpio_conf;

        gpio_array_size = of_gpio_count(of_node);
        CDBG("%s gpio count %d\n", __func__, gpio_array_size);

        if (gpio_array_size) {
            gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
                                 GFP_KERNEL);
            if (!gpio_array) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                rc = -ENOMEM;
                goto ERROR4;
            }
            for (i = 0; i < gpio_array_size; i++) {
                gpio_array[i] = of_get_gpio(of_node, i);
                CDBG("%s gpio_array[%d] = %d\n", __func__, i,
                     gpio_array[i]);
            }

            rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
                                                gpio_array, gpio_array_size);
            if (rc < 0) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                goto ERROR4;
            }

            rc = msm_camera_get_dt_gpio_set_tbl(of_node, gconf,
                                                gpio_array, gpio_array_size);
            if (rc < 0) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                goto ERROR5;
            }

            rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
                                              gpio_array, gpio_array_size);
            if (rc < 0) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                goto ERROR6;
            }
        }

        /* Read the max current for an LED if present */
        if (of_get_property(of_node, "qcom,max-current", &count)) {
            count /= sizeof(uint32_t);

            if (count > MAX_LED_TRIGGERS) {
                pr_err("failed\n");
                rc = -EINVAL;
                goto ERROR8;
            }

            fctrl->flash_num_sources = count;
            fctrl->torch_num_sources = count;

            rc = of_property_read_u32_array(of_node,
                                            "qcom,max-current",
                                            fctrl->flash_max_current, count);
            if (rc < 0) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                goto ERROR8;
            }

            for (; count < MAX_LED_TRIGGERS; count++)
                fctrl->flash_max_current[count] = 0;

            for (count = 0; count < MAX_LED_TRIGGERS; count++)
                fctrl->torch_max_current[count] =
                    fctrl->flash_max_current[count] >> 1;
        }

        /* Read the max duration for an LED if present */
        if (of_get_property(of_node, "qcom,max-duration", &count)) {
            count /= sizeof(uint32_t);

            if (count > MAX_LED_TRIGGERS) {
                pr_err("failed\n");
                rc = -EINVAL;
                goto ERROR8;
            }

            rc = of_property_read_u32_array(of_node,
                                            "qcom,max-duration",
                                            fctrl->flash_max_duration, count);
            if (rc < 0) {
                pr_err("%s failed %d\n", __func__, __LINE__);
                goto ERROR8;
            }

            for (; count < MAX_LED_TRIGGERS; count++)
                fctrl->flash_max_duration[count] = 0;
        }

        flashdata->slave_info =
            kzalloc(sizeof(struct msm_camera_slave_info),
                    GFP_KERNEL);
        if (!flashdata->slave_info) {
            pr_err("%s failed %d\n", __func__, __LINE__);
            rc = -ENOMEM;
            goto ERROR8;
        }

        rc = of_property_read_u32_array(of_node, "qcom,slave-id",
                                        id_info, 3);
        if (rc < 0) {
            pr_err("%s failed %d\n", __func__, __LINE__);
            goto ERROR9;
        }
        fctrl->flashdata->slave_info->sensor_slave_addr = id_info[0];
        fctrl->flashdata->slave_info->sensor_id_reg_addr = id_info[1];
        fctrl->flashdata->slave_info->sensor_id = id_info[2];

        kfree(gpio_array);
        return rc;
ERROR9:
        kfree(fctrl->flashdata->slave_info);
ERROR8:
        kfree(fctrl->flashdata->power_info.gpio_conf->gpio_num_info);
ERROR6:
        kfree(gconf->cam_gpio_set_tbl);
ERROR5:
        kfree(gconf->cam_gpio_req_tbl);
ERROR4:
        kfree(gconf);
ERROR1:
        kfree(fctrl->flashdata);
        kfree(gpio_array);
    }
Exemplo n.º 16
0
/*!
   \brief This function is called by module management in 2.6 kernel or by ifxusb_driver_init with 2.4 kernel
  It is to probe and setup IFXUSB core(s).
*/
static int ifxusb_driver_probe(struct platform_device *_pdev)
{
	int retval = 0;
	struct device_node *np;
	int gpio_count;
	u32 port_mask = 0x1;

#ifdef __IS_DANUBE__
        np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-danube");
#elif defined __IS_AMAZON_SE__
        np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-ase");
#elif defined __IS_AR9__
        np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-arx100");
#elif defined __IS_VR9__
        np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-xrx200");
#elif defined __IS_AR10__
        np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-arx300");
#endif
	if (!np) {
		dev_err(&_pdev->dev, "failed to find hcd device node\n");
		return -ENODEV;
	}
	of_property_read_u32(np, "lantiq,portmask", &port_mask);
	// Parsing and store the parameters
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	parse_parms();

	#ifdef __IS_HOST__
		#if defined(__DO_OC_INT__)
			if(!oc_int_id)
			{
				#if   defined(__IS_DUAL__)
					oc_int_id=&ifxusb_hcd_1;
					oc_int_id_1=&ifxusb_hcd_1;
					oc_int_id_2=&ifxusb_hcd_2;
				#else
					oc_int_id=&ifxusb_hcd;
				#endif
			}
		#endif

		#if   defined(__IS_DUAL__)
			memset(&ifxusb_hcd_1, 0, sizeof(ifxhcd_hcd_t));
			memset(&ifxusb_hcd_2, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd_1.core_if.core_no=0;
			ifxusb_hcd_2.core_if.core_no=1;
			ifxusb_hcd_1.core_if.core_name=(char *)ifxusb_hcd_name_1;
			ifxusb_hcd_2.core_if.core_name=(char *)ifxusb_hcd_name_2;

			ifxusb_hcd_1.dev=&_pdev->dev;
			ifxusb_hcd_2.dev=&_pdev->dev;

			if (port_mask & 0x1) {
				retval = ifxusb_driver_probe_h(&ifxusb_hcd_1,
			                               IFXUSB1_IRQ,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                               );
				if(retval)
					goto ifxusb_driver_probe_fail;
			}

			if (port_mask & 0x2) {
				retval = ifxusb_driver_probe_h(&ifxusb_hcd_2,
			                               IFXUSB2_IRQ,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
				if(retval)
					goto ifxusb_driver_probe_fail;
			}
		#elif defined(__IS_FIRST__)
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=0;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_pdev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFXUSB1_IRQ,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;

		#elif defined(__IS_SECOND__)
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=1;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_pdev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFXUSB2_IRQ,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;

		#else
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=0;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_pdev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFXUSB_IRQ,
			                               IFXUSB_IOMEM_BASE,
			                               IFXUSB_FIFOMEM_BASE,
			                               IFXUSB_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;
		#endif
	#endif

	#ifdef __IS_DEVICE__
		memset(&ifxusb_pcd, 0, sizeof(ifxpcd_pcd_t));
		ifxusb_pcd.core_if.core_name=(char *)&ifxusb_pcd_name[0];

		ifxusb_pcd.dev=&_pdev->dev;

		#if   defined(__IS_FIRST__)
			ifxusb_pcd.core_if.core_no=0;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB1_IRQ,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                              );
		#elif defined(__IS_SECOND__)
			ifxusb_pcd.core_if.core_no=1;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB2_IRQ,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
		#else
			ifxusb_pcd.core_if.core_no=0;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB_IRQ,
			                               IFXUSB_IOMEM_BASE,
			                               IFXUSB_FIFOMEM_BASE,
			                               IFXUSB_FIFODBG_BASE
			                              );
		#endif
		if(retval)
			goto ifxusb_driver_probe_fail;
	#endif

/*	#ifdef __IS_HOST__
		ifxusb_attr_create_h(&_pdev->dev);
	#else
		ifxusb_attr_create_d(&_pdev->dev);
	#endif*/

	gpio_count = of_gpio_count(np);
	while (gpio_count > 0) {
		enum of_gpio_flags flags;
		int gpio = of_get_gpio_flags(np, --gpio_count, &flags);
		if (gpio_request(gpio, "usb"))
			continue;
		dev_info(&_pdev->dev, "requested GPIO %d\n", gpio);
		gpio_direction_output(gpio, (flags & OF_GPIO_ACTIVE_LOW) ? (0) : (1));
	}


	return 0;

ifxusb_driver_probe_fail:
	ifxusb_driver_remove(_pdev);
	return retval;
}
Exemplo n.º 17
0
static int s2mps16_pmic_dt_parse_pdata(struct sec_pmic_dev *iodev,
					struct sec_platform_data *pdata)
{
	struct device_node *pmic_np, *regulators_np, *reg_np;
	struct sec_regulator_data *rdata;
	unsigned int i, s2mps16_desc_type;
	int ret;
	u32 val;
	pdata->smpl_warn_vth = 0;
	pdata->smpl_warn_hys = 0;

	pmic_np = iodev->dev->of_node;
	if (!pmic_np) {
		dev_err(iodev->dev, "could not find pmic sub-node\n");
		return -ENODEV;
	}
	/* get 2 gpio values */
	if (of_gpio_count(pmic_np) < 2) {
		dev_err(iodev->dev, "could not find pmic gpios\n");
		return -EINVAL;
	}
	pdata->smpl_warn = of_get_gpio(pmic_np, 0);
	pdata->dvs_pin = of_get_gpio(pmic_np, 1);

	ret = of_property_read_u32(pmic_np, "cache_data", &val);
	if (ret)
		return -EINVAL;
	pdata->cache_data = !!val;

	ret = of_property_read_u32(pmic_np, "g3d_en", &val);
	if (ret)
		return -EINVAL;
	pdata->g3d_en = !!val;

	ret = of_property_read_u32(pmic_np, "dvs_en", &val);
	if (ret)
		return -EINVAL;
	pdata->dvs_en = !!val;

	ret = of_property_read_u32(pmic_np, "smpl_warn_en", &val);
	if (ret)
		return -EINVAL;
	pdata->smpl_warn_en = !!val;

	ret = of_property_read_u32(pmic_np, "smpl_warn_vth", &val);
	if (ret)
		return -EINVAL;
	pdata->smpl_warn_vth = val;

	ret = of_property_read_u32(pmic_np, "smpl_warn_hys", &val);
	if (ret)
		return -EINVAL;
	pdata->smpl_warn_hys = val;

	ret = of_property_read_u32(pmic_np, "ldo8_7_seq", &val);
	if (ret)
		pdata->ldo8_7_seq = 0x05;
	else
		pdata->ldo8_7_seq = val;

	ret = of_property_read_u32(pmic_np, "ldo10_9_seq", &val);
	if (ret)
		pdata->ldo10_9_seq = 0x61;
	else
		pdata->ldo10_9_seq = val;

	pdata->adc_en = false;
	if (of_find_property(pmic_np, "adc-on", NULL))
		pdata->adc_en = true;
	iodev->adc_en = pdata->adc_en;

	pdata->buck_dvs_on = (of_find_property(pmic_np, "buck_dvs_on", NULL))
			? true : false;

	regulators_np = of_find_node_by_name(pmic_np, "regulators");
	if (!regulators_np) {
		dev_err(iodev->dev, "could not find regulators sub-node\n");
		return -EINVAL;
	}

	/* count the number of regulators to be supported in pmic */
	pdata->num_regulators = 0;
	for_each_child_of_node(regulators_np, reg_np) {
		pdata->num_regulators++;
	}

	rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
				pdata->num_regulators, GFP_KERNEL);
	if (!rdata) {
		dev_err(iodev->dev,
			"could not allocate memory for regulator data\n");
		return -ENOMEM;
	}

	pdata->regulators = rdata;
	s2mps16_desc_type = S2MPS16_DESC_TYPE0;
	for_each_child_of_node(regulators_np, reg_np) {
		for (i = 0; i < ARRAY_SIZE(regulators[s2mps16_desc_type]); i++)
			if (!of_node_cmp(reg_np->name,
					regulators[s2mps16_desc_type][i].name))
				break;

		if (i == ARRAY_SIZE(regulators[s2mps16_desc_type])) {
			dev_warn(iodev->dev,
			"don't know how to configure regulator %s\n",
			reg_np->name);
			continue;
		}

		rdata->id = i;
		rdata->initdata = of_get_regulator_init_data(
						iodev->dev, reg_np);
		rdata->reg_node = reg_np;
		rdata++;
	}

	return 0;
}
static int32_t msm_led_get_dt_data(struct device_node *of_node,
		struct msm_led_flash_ctrl_t *fctrl)
{
	int32_t rc = 0, i = 0;
	struct msm_camera_gpio_conf *gconf = NULL;
	struct device_node *flash_src_node = NULL;
	struct msm_camera_sensor_board_info *flashdata = NULL;
	uint32_t count = 0;
	uint16_t *gpio_array = NULL;
	uint16_t gpio_array_size = 0;
	uint32_t id_info[3];

	CDBG("called\n");

	if (!of_node) {
		pr_err("of_node NULL\n");
		return -EINVAL;
	}

	fctrl->flashdata = kzalloc(sizeof(
		struct msm_camera_sensor_board_info),
		GFP_KERNEL);
	if (!fctrl->flashdata) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}

	flashdata = fctrl->flashdata;

	flashdata->sensor_init_params = kzalloc(sizeof(
		struct msm_sensor_init_params), GFP_KERNEL);
	if (!flashdata->sensor_init_params) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}

	rc = of_property_read_u32(of_node, "cell-index", &fctrl->subdev_id);
	if (rc < 0) {
		pr_err("failed\n");
		return -EINVAL;
	}

	CDBG("subdev id %d\n", fctrl->subdev_id);

	rc = of_property_read_string(of_node, "qcom,flash-name",
		&flashdata->sensor_name);
	CDBG("%s qcom,flash-name %s, rc %d\n", __func__,
		flashdata->sensor_name, rc);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto ERROR1;
	}

	if (of_get_property(of_node, "qcom,flash-source", &count)) {
		count /= sizeof(uint32_t);
		CDBG("count %d\n", count);
		if (count > MAX_LED_TRIGGERS) {
			pr_err("failed\n");
			return -EINVAL;
		}
		for (i = 0; i < count; i++) {
			flash_src_node = of_parse_phandle(of_node,
				"qcom,flash-source", i);
			if (!flash_src_node) {
				pr_err("flash_src_node NULL\n");
				continue;
			}

			rc = of_property_read_string(flash_src_node,
				"linux,default-trigger",
				&fctrl->led_trigger_name[i]);
			if (rc < 0) {
				pr_err("failed\n");
				of_node_put(flash_src_node);
				continue;
			}

			CDBG("default trigger %s\n",
				 fctrl->led_trigger_name[i]);

			rc = of_property_read_u32(flash_src_node,
				"qcom,max-current",
				&fctrl->op_current[i]);
			if (rc < 0) {
				pr_err("failed rc %d\n", rc);
				of_node_put(flash_src_node);
				continue;
			}

			of_node_put(flash_src_node);

			CDBG("max_current[%d] %d\n",
				i, fctrl->op_current[i]);

			led_trigger_register_simple(
				fctrl->led_trigger_name[i],
				&fctrl->led_trigger[i]);
		}

	} else { 
		flashdata->gpio_conf =
			 kzalloc(sizeof(struct msm_camera_gpio_conf),
				 GFP_KERNEL);
		if (!flashdata->gpio_conf) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			return rc;
		}
		gconf = flashdata->gpio_conf;

		gpio_array_size = of_gpio_count(of_node);
		CDBG("%s gpio count %d\n", __func__, gpio_array_size);

		if (gpio_array_size) {
			gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
				GFP_KERNEL);
			if (!gpio_array) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				rc = -ENOMEM;
				goto ERROR4;
			}
			for (i = 0; i < gpio_array_size; i++) {
				gpio_array[i] = of_get_gpio(of_node, i);
				CDBG("%s gpio_array[%d] = %d\n", __func__, i,
					gpio_array[i]);
			}

			rc = msm_sensor_get_dt_gpio_req_tbl(of_node, gconf,
				gpio_array, gpio_array_size);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR4;
			}

			rc = msm_sensor_get_dt_gpio_set_tbl(of_node, gconf,
				gpio_array, gpio_array_size);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR5;
			}

			rc = msm_flash_init_gpio_pin_tbl(of_node, gconf,
				gpio_array, gpio_array_size);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR6;
			}
		}

		flashdata->slave_info =
			kzalloc(sizeof(struct msm_camera_slave_info),
				GFP_KERNEL);
		if (!flashdata->slave_info) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto ERROR8;
		}

		rc = of_property_read_u32_array(of_node, "qcom,slave-id",
			id_info, 3);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR9;
		}
		fctrl->flashdata->slave_info->sensor_slave_addr = id_info[0];
		fctrl->flashdata->slave_info->sensor_id_reg_addr = id_info[1];
		fctrl->flashdata->slave_info->sensor_id = id_info[2];

		kfree(gpio_array);
		return rc;
ERROR9:
		kfree(fctrl->flashdata->slave_info);
ERROR8:
		kfree(fctrl->flashdata->gpio_conf->gpio_num_info);
ERROR6:
		kfree(gconf->cam_gpio_set_tbl);
ERROR5:
		kfree(gconf->cam_gpio_req_tbl);
ERROR4:
		kfree(gconf);
ERROR1:
		kfree(fctrl->flashdata);
		kfree(gpio_array);
	}
	return rc;
}
Exemplo n.º 19
0
static int msm_eeprom_get_dt_data(struct msm_eeprom_ctrl_t *e_ctrl)
{
	int rc = 0, i = 0;
	struct msm_eeprom_board_info *eb_info;
	struct msm_camera_power_ctrl_t *power_info =
		&e_ctrl->eboard_info->power_info;
	struct spi_device *spi = e_ctrl->i2c_client.spi_client->spi_master;
	struct device_node *of_node = spi->dev.of_node;
	struct msm_camera_gpio_conf *gconf = NULL;
	uint16_t gpio_array_size = 0;
	uint16_t *gpio_array = NULL;

	eb_info = e_ctrl->eboard_info;
	rc = msm_camera_get_dt_power_setting_data(spi->dev.of_node,
		  &power_info->power_setting, &power_info->power_setting_size);
	if (rc)
		return rc;

	rc = msm_camera_get_dt_vreg_data(of_node, &power_info->cam_vreg,
					     &power_info->num_vreg);
	if (rc)
		goto ERROR1;

	power_info->gpio_conf = kzalloc(sizeof(struct msm_camera_gpio_conf),
					GFP_KERNEL);
	if (!power_info->gpio_conf) {
		rc = -ENOMEM;
		goto ERROR2;
	}
	gconf = power_info->gpio_conf;
	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size) {
		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
			GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR3;
		}
		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			CDBG("%s gpio_array[%d] = %d\n", __func__, i,
				gpio_array[i]);
		}

		rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR4;
		}

		rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR4;
		}
		kfree(gpio_array);
	}

	return rc;
ERROR4:
	kfree(gpio_array);
ERROR3:
	kfree(power_info->gpio_conf);
ERROR2:
	kfree(power_info->cam_vreg);
ERROR1:
	kfree(power_info->power_setting);
	return rc;
}
int hw_sensor_get_dt_data(struct platform_device *pdev,
	sensor_t *sensor)
{
	struct device_node *of_node = pdev->dev.of_node;
	hwsensor_board_info_t *sensor_info = NULL;
	int rc = 0;
	u32 i, index = 0;
	char *gpio_tag = NULL;
	const char *gpio_ctrl_types[IO_MAX] =
		{"reset", "fsin", "pwdn", "vcm_pwdn", "suspend", "reset2"};

	cam_debug("enter %s", __func__);
	sensor_info = kzalloc(sizeof(hwsensor_board_info_t),
				GFP_KERNEL);
	if (!sensor_info) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}
	sensor->board_info= sensor_info;

	rc = of_property_read_string(of_node, "huawei,sensor_name",
		&sensor_info->name);
	cam_debug("%s huawei,sensor_name %s, rc %d\n", __func__,
		sensor_info->name, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,sensor_index",
		&sensor_info->sensor_index);
	cam_debug("%s huawei,sensor_index %d, rc %d\n", __func__,
		sensor_info->sensor_index, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,interface_type",
		&sensor_info->interface_type);
	cam_debug("%s huawei,interface_type %d, rc %d\n", __func__,
		sensor_info->interface_type, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,csi_lane",
		&sensor_info->csi_lane);
	cam_debug("%s huawei,csi_lane %d, rc %d\n", __func__,
		sensor_info->csi_lane, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,csi_mipi_clk",
		&sensor_info->csi_mipi_clk);
	cam_debug("%s huawei,csi_mipi_clk %d, rc %d\n", __func__,
		sensor_info->csi_mipi_clk, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,csi_index",
		&sensor_info->csi_index);
	cam_debug("%s huawei,csi_index %d, rc %d\n", __func__,
		sensor_info->csi_index, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,pd_valid",
		&sensor_info->power_conf.pd_valid);
	cam_debug("%s huawei,pd_valid %d, rc %d\n", __func__,
		sensor_info->power_conf.pd_valid, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,reset_valid",
		&sensor_info->power_conf.reset_valid);
	cam_debug("%s huawei,reset_valid %d, rc %d\n", __func__,
		sensor_info->power_conf.reset_valid, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,vcmpd_valid",
		&sensor_info->power_conf.vcmpd_valid);
	cam_debug("%s huawei,vcmpd_valid %d, rc %d\n", __func__,
		sensor_info->power_conf.vcmpd_valid, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,i2c-index",
		&sensor_info->i2c_config.index);
	cam_debug("%s huawei,i2c-index %d, rc %d\n", __func__,
		sensor_info->i2c_config.index, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,i2c-speed",
		&sensor_info->i2c_config.speed);
	cam_debug("%s huawei,i2c-speed %d, rc %d\n", __func__,
		sensor_info->i2c_config.speed, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,i2c-addr",
		&sensor_info->i2c_config.addr);
	cam_debug("%s huawei,i2c-addr 0x%x, rc %d\n", __func__,
		sensor_info->i2c_config.addr, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,i2c-addr_bits",
		&sensor_info->i2c_config.addr_bits);
	cam_debug("%s huawei,i2c-addr_bits %d, rc %d\n", __func__,
		sensor_info->i2c_config.addr_bits, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,i2c-val_bits",
		&sensor_info->i2c_config.val_bits);
	cam_debug("%s huawei,i2c-val_bits %d, rc %d\n", __func__,
		sensor_info->i2c_config.val_bits, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,sensor_chipid",
		&sensor_info->sensor_chipid);
	cam_debug("%s huawei,sensor_chipid 0x%x, rc %d\n", __func__,
		sensor_info->sensor_chipid, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,camif_id",
		&sensor_info->camif_id);
	cam_debug("%s huawei,camif_id 0x%x, rc %d\n", __func__,
		sensor_info->camif_id, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,vcm_enable",
		&sensor_info->vcm_enable);
	cam_debug("%s huawei,vcm_enable %d, rc %d\n", __func__,
		sensor_info->vcm_enable, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	rc = of_property_read_u32(of_node, "huawei,sensor_type",
		&sensor_info->sensor_type);
	cam_debug("%s huawei,sensor_type %d, rc %d\n", __func__,
		sensor_info->sensor_type, rc);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	if (sensor_info->vcm_enable) {
		rc = of_property_read_string(of_node, "huawei,vcm_name",
			&sensor_info->vcm_name);
		cam_debug("%s huawei,vcm_name %s, rc %d\n", __func__,
			sensor_info->vcm_name, rc);
		if (rc < 0) {
			cam_err("%s failed %d\n", __func__, __LINE__);
			goto fail;
		}
	}

	if (hw_is_fpga_board())
		return rc;

	/* get ldo */
	sensor_info->ldo_num = of_property_count_strings(of_node, "huawei,ldo-names");
	if(sensor_info->ldo_num < 0) {
			cam_err("%s failed %d\n", __func__, __LINE__);
			goto fail;
	}
	cam_debug("ldo num = %d", sensor_info->ldo_num);
	for (i = 0; i < sensor_info->ldo_num; i++) {
		rc = of_property_read_string_index(of_node, "huawei,ldo-names",
			i, &sensor_info->ldo[i].supply);
		if(rc < 0) {
			cam_err("%s failed %d\n", __func__, __LINE__);
			goto fail;
		}
	}

	rc = devm_regulator_bulk_get(&(pdev->dev), sensor_info->ldo_num, sensor_info->ldo);
	if (rc < 0) {
		cam_err("%s failed %d\n", __func__, __LINE__);
		goto fail;
	}

	sensor_info->gpio_num = of_gpio_count(of_node);
	if(sensor_info->gpio_num < 0 ) {
			cam_err("%s failed %d\n", __func__, __LINE__);
			goto fail;
	}
	for(i = 0; i < sensor_info->gpio_num; i++) {
		rc = of_property_read_string_index(of_node, "huawei,gpio-ctrl-types",
			i, (const char **)&gpio_tag);
		if(rc < 0) {
			cam_err("%s failed %d\n", __func__, __LINE__);
			goto fail;
		}
		for(index = 0; index < IO_MAX; index++) {
			if(!strcmp(gpio_ctrl_types[index], gpio_tag))
				sensor_info->gpios[index].gpio = of_get_gpio(of_node, i);
		}
		cam_info("gpio ctrl types: %s\n", gpio_tag);
	}

	return rc;
fail:
	cam_err("%s error exit.\n", __func__);
	kfree(sensor_info);
	sensor_info = NULL;
	return rc;
}
Exemplo n.º 21
0
/*
 * OF Platform Bus Binding
 */
static int __devinit mpc52xx_spi_probe(struct platform_device *op,
				       const struct of_device_id *match)
{
	struct spi_master *master;
	struct mpc52xx_spi *ms;
	void __iomem *regs;
	u8 ctrl1;
	int rc, i = 0;
	int gpio_cs;

	/* MMIO registers */
	dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
	regs = of_iomap(op->dev.of_node, 0);
	if (!regs)
		return -ENODEV;

	/* initialize the device */
	ctrl1 = SPI_CTRL1_SPIE | SPI_CTRL1_SPE | SPI_CTRL1_MSTR;
	out_8(regs + SPI_CTRL1, ctrl1);
	out_8(regs + SPI_CTRL2, 0x0);
	out_8(regs + SPI_DATADIR, 0xe);	/* Set output pins */
	out_8(regs + SPI_PORTDATA, 0x8);	/* Deassert /SS signal */

	/* Clear the status register and re-read it to check for a MODF
	 * failure.  This driver cannot currently handle multiple masters
	 * on the SPI bus.  This fault will also occur if the SPI signals
	 * are not connected to any pins (port_config setting) */
	in_8(regs + SPI_STATUS);
	out_8(regs + SPI_CTRL1, ctrl1);

	in_8(regs + SPI_DATA);
	if (in_8(regs + SPI_STATUS) & SPI_STATUS_MODF) {
		dev_err(&op->dev, "mode fault; is port_config correct?\n");
		rc = -EIO;
		goto err_init;
	}

	dev_dbg(&op->dev, "allocating spi_master struct\n");
	master = spi_alloc_master(&op->dev, sizeof *ms);
	if (!master) {
		rc = -ENOMEM;
		goto err_alloc;
	}

	master->bus_num = -1;
	master->setup = mpc52xx_spi_setup;
	master->transfer = mpc52xx_spi_transfer;
	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
	master->dev.of_node = op->dev.of_node;

	dev_set_drvdata(&op->dev, master);

	ms = spi_master_get_devdata(master);
	ms->master = master;
	ms->regs = regs;
	ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0);
	ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1);
	ms->state = mpc52xx_spi_fsmstate_idle;
	ms->ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node);
	ms->gpio_cs_count = of_gpio_count(op->dev.of_node);
	if (ms->gpio_cs_count > 0) {
		master->num_chipselect = ms->gpio_cs_count;
		ms->gpio_cs = kmalloc(ms->gpio_cs_count * sizeof(unsigned int),
				GFP_KERNEL);
		if (!ms->gpio_cs) {
			rc = -ENOMEM;
			goto err_alloc;
		}

		for (i = 0; i < ms->gpio_cs_count; i++) {
			gpio_cs = of_get_gpio(op->dev.of_node, i);
			if (gpio_cs < 0) {
				dev_err(&op->dev,
					"could not parse the gpio field "
					"in oftree\n");
				rc = -ENODEV;
				goto err_gpio;
			}

			rc = gpio_request(gpio_cs, dev_name(&op->dev));
			if (rc) {
				dev_err(&op->dev,
					"can't request spi cs gpio #%d "
					"on gpio line %d\n", i, gpio_cs);
				goto err_gpio;
			}

			gpio_direction_output(gpio_cs, 1);
			ms->gpio_cs[i] = gpio_cs;
		}
	} else {
		master->num_chipselect = 1;
	}

	spin_lock_init(&ms->lock);
	INIT_LIST_HEAD(&ms->queue);
	INIT_WORK(&ms->work, mpc52xx_spi_wq);

	/* Decide if interrupts can be used */
	if (ms->irq0 && ms->irq1) {
		rc = request_irq(ms->irq0, mpc52xx_spi_irq, 0,
				  "mpc5200-spi-modf", ms);
		rc |= request_irq(ms->irq1, mpc52xx_spi_irq, 0,
				  "mpc5200-spi-spif", ms);
		if (rc) {
			free_irq(ms->irq0, ms);
			free_irq(ms->irq1, ms);
			ms->irq0 = ms->irq1 = 0;
		}
	} else {
		/* operate in polled mode */
		ms->irq0 = ms->irq1 = 0;
	}

	if (!ms->irq0)
		dev_info(&op->dev, "using polled mode\n");

	dev_dbg(&op->dev, "registering spi_master struct\n");
	rc = spi_register_master(master);
	if (rc)
		goto err_register;

	dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");

	return rc;

 err_register:
	dev_err(&ms->master->dev, "initialization failed\n");
	spi_master_put(master);
 err_gpio:
	while (i-- > 0)
		gpio_free(ms->gpio_cs[i]);

	kfree(ms->gpio_cs);
 err_alloc:
 err_init:
	iounmap(regs);
	return rc;
}
Exemplo n.º 22
0
static struct gpio_regulator_config *
of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
{
	struct gpio_regulator_config *config;
	struct property *prop;
	const char *regtype;
	int proplen, gpio, i;
	int ret;

	config = devm_kzalloc(dev,
			sizeof(struct gpio_regulator_config),
			GFP_KERNEL);
	if (!config)
		return ERR_PTR(-ENOMEM);

	config->init_data = of_get_regulator_init_data(dev, np);
	if (!config->init_data)
		return ERR_PTR(-EINVAL);

	config->supply_name = config->init_data->constraints.name;

	if (of_property_read_bool(np, "enable-active-high"))
		config->enable_high = true;

	if (of_property_read_bool(np, "enable-at-boot"))
		config->enabled_at_boot = true;

	of_property_read_u32(np, "startup-delay-us", &config->startup_delay);

	config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);

	/* Fetch GPIOs. */
	config->nr_gpios = of_gpio_count(np);

	config->gpios = devm_kzalloc(dev,
				sizeof(struct gpio) * config->nr_gpios,
				GFP_KERNEL);
	if (!config->gpios)
		return ERR_PTR(-ENOMEM);

	prop = of_find_property(np, "gpios-states", NULL);
	if (prop) {
		proplen = prop->length / sizeof(int);
		if (proplen != config->nr_gpios) {
			/* gpios <-> gpios-states mismatch */
			prop = NULL;
		}
	}

	for (i = 0; i < config->nr_gpios; i++) {
		gpio = of_get_named_gpio(np, "gpios", i);
		if (gpio < 0)
			break;
		config->gpios[i].gpio = gpio;
		if (prop && be32_to_cpup((int *)prop->value + i))
			config->gpios[i].flags = GPIOF_OUT_INIT_HIGH;
	}

	/* Fetch states. */
	prop = of_find_property(np, "states", NULL);
	if (!prop) {
		dev_err(dev, "No 'states' property found\n");
		return ERR_PTR(-EINVAL);
	}

	proplen = prop->length / sizeof(int);

	config->states = devm_kzalloc(dev,
				sizeof(struct gpio_regulator_state)
				* (proplen / 2),
				GFP_KERNEL);
	if (!config->states)
		return ERR_PTR(-ENOMEM);

	for (i = 0; i < proplen / 2; i++) {
		config->states[i].value =
			be32_to_cpup((int *)prop->value + (i * 2));
		config->states[i].gpios =
			be32_to_cpup((int *)prop->value + (i * 2 + 1));
	}
	config->nr_states = i;

	config->type = REGULATOR_VOLTAGE;
	ret = of_property_read_string(np, "regulator-type", &regtype);
	if (ret >= 0) {
		if (!strncmp("voltage", regtype, 7))
			config->type = REGULATOR_VOLTAGE;
		else if (!strncmp("current", regtype, 7))
			config->type = REGULATOR_CURRENT;
		else
			dev_warn(dev, "Unknown regulator-type '%s'\n",
				 regtype);
	}

	return config;
}
Exemplo n.º 23
0
static struct gpio_regulator_config *
of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
			     const struct regulator_desc *desc)
{
	struct gpio_regulator_config *config;
	const char *regtype;
	int proplen, gpio, i;
	int ret;

	config = devm_kzalloc(dev,
			sizeof(struct gpio_regulator_config),
			GFP_KERNEL);
	if (!config)
		return ERR_PTR(-ENOMEM);

	config->init_data = of_get_regulator_init_data(dev, np, desc);
	if (!config->init_data)
		return ERR_PTR(-EINVAL);

	config->supply_name = config->init_data->constraints.name;

	if (of_property_read_bool(np, "enable-active-high"))
		config->enable_high = true;

	if (of_property_read_bool(np, "enable-at-boot"))
		config->enabled_at_boot = true;

	of_property_read_u32(np, "startup-delay-us", &config->startup_delay);

	config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
	if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT)
		return ERR_PTR(config->enable_gpio);

	/* Fetch GPIOs. - optional property*/
	ret = of_gpio_count(np);
	if ((ret < 0) && (ret != -ENOENT))
		return ERR_PTR(ret);

	if (ret > 0) {
		config->nr_gpios = ret;
		config->gpios = devm_kzalloc(dev,
					sizeof(struct gpio) * config->nr_gpios,
					GFP_KERNEL);
		if (!config->gpios)
			return ERR_PTR(-ENOMEM);

		proplen = of_property_count_u32_elems(np, "gpios-states");
		/* optional property */
		if (proplen < 0)
			proplen = 0;

		if (proplen > 0 && proplen != config->nr_gpios) {
			dev_warn(dev, "gpios <-> gpios-states mismatch\n");
			proplen = 0;
		}

		for (i = 0; i < config->nr_gpios; i++) {
			gpio = of_get_named_gpio(np, "gpios", i);
			if (gpio < 0) {
				if (gpio != -ENOENT)
					return ERR_PTR(gpio);
				break;
			}
			config->gpios[i].gpio = gpio;
			if (proplen > 0) {
				of_property_read_u32_index(np, "gpios-states",
							   i, &ret);
				if (ret)
					config->gpios[i].flags =
							   GPIOF_OUT_INIT_HIGH;
			}
		}
	}

	/* Fetch states. */
	proplen = of_property_count_u32_elems(np, "states");
	if (proplen < 0) {
		dev_err(dev, "No 'states' property found\n");
		return ERR_PTR(-EINVAL);
	}

	config->states = devm_kzalloc(dev,
				sizeof(struct gpio_regulator_state)
				* (proplen / 2),
				GFP_KERNEL);
	if (!config->states)
		return ERR_PTR(-ENOMEM);

	for (i = 0; i < proplen / 2; i++) {
		of_property_read_u32_index(np, "states", i * 2,
					   &config->states[i].value);
		of_property_read_u32_index(np, "states", i * 2 + 1,
					   &config->states[i].gpios);
	}
	config->nr_states = i;

	config->type = REGULATOR_VOLTAGE;
	ret = of_property_read_string(np, "regulator-type", &regtype);
	if (ret >= 0) {
		if (!strncmp("voltage", regtype, 7))
			config->type = REGULATOR_VOLTAGE;
		else if (!strncmp("current", regtype, 7))
			config->type = REGULATOR_CURRENT;
		else
			dev_warn(dev, "Unknown regulator-type '%s'\n",
				 regtype);
	}

	return config;
}
Exemplo n.º 24
0
static int32_t msm_sensor_get_dt_data(struct device_node *of_node,
	struct msm_sensor_ctrl_t *s_ctrl)
{
	int32_t rc = 0, i = 0, ret = 0;
	struct msm_camera_gpio_conf *gconf = NULL;
	struct msm_camera_sensor_board_info *sensordata = NULL;
	uint16_t *gpio_array = NULL;
	uint16_t gpio_array_size = 0;
	uint32_t id_info[3];

	s_ctrl->sensordata = kzalloc(sizeof(
		struct msm_camera_sensor_board_info),
		GFP_KERNEL);
	if (!s_ctrl->sensordata) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}

	sensordata = s_ctrl->sensordata;

	rc = of_property_read_string(of_node, "qcom,sensor-name",
		&sensordata->sensor_name);
	CDBG("%s qcom,sensor-name %s, rc %d\n", __func__,
		sensordata->sensor_name, rc);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_SENSORDATA;
	}

	rc = of_property_read_u32(of_node, "qcom,cci-master",
		&s_ctrl->cci_i2c_master);
	CDBG("%s qcom,cci-master %d, rc %d\n", __func__, s_ctrl->cci_i2c_master,
		rc);
	if (rc < 0) {
		/* Set default master 0 */
		s_ctrl->cci_i2c_master = MASTER_0;
		rc = 0;
	}

	rc = msm_sensor_get_sub_module_index(of_node, &sensordata->sensor_info);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_SENSORDATA;
	}

	/* Get sensor mount angle */
	rc = of_property_read_u32(of_node, "qcom,mount-angle",
		&sensordata->sensor_info->sensor_mount_angle);
	CDBG("%s qcom,mount-angle %d, rc %d\n", __func__,
		sensordata->sensor_info->sensor_mount_angle, rc);
	if (rc < 0) {
		/* Invalidate mount angle flag */
		pr_err("%s Default sensor mount angle %d\n",
					__func__, __LINE__);
		sensordata->sensor_info->is_mount_angle_valid = 0;
		sensordata->sensor_info->sensor_mount_angle = 0;
		rc = 0;
	} else {
		sensordata->sensor_info->is_mount_angle_valid = 1;
	}

	rc = of_property_read_u32(of_node, "qcom,sensor-position",
		&sensordata->sensor_info->position);
	CDBG("%s qcom,sensor-position %d, rc %d\n", __func__,
		sensordata->sensor_info->position, rc);
	if (rc < 0) {
		pr_err("%s Default sensor position %d\n", __func__, __LINE__);
		sensordata->sensor_info->position = 0;
		rc = 0;
	}

	rc = of_property_read_u32(of_node, "qcom,sensor-mode",
		&sensordata->sensor_info->modes_supported);
	CDBG("%s qcom,sensor-mode %d, rc %d\n", __func__,
		sensordata->sensor_info->modes_supported, rc);
	if (rc < 0) {
		pr_err("%s Default sensor mode %d\n", __func__, __LINE__);
		sensordata->sensor_info->modes_supported = 0;
		rc = 0;
	}

	rc = msm_sensor_get_dt_csi_data(of_node, &sensordata->csi_lane_params);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_SENSOR_INFO;
	}

	rc = msm_camera_get_dt_vreg_data(of_node,
			&sensordata->power_info.cam_vreg,
			&sensordata->power_info.num_vreg);
	if (rc < 0)
		goto FREE_CSI;

	rc = msm_camera_get_dt_power_setting_data(of_node,
			sensordata->power_info.cam_vreg,
			sensordata->power_info.num_vreg,
			&sensordata->power_info);


	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_VREG;
	}


	rc = msm_camera_get_power_settimgs_from_sensor_lib(
			&sensordata->power_info,
			&s_ctrl->power_setting_array);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_VREG;
	}

	sensordata->power_info.gpio_conf = kzalloc(
			sizeof(struct msm_camera_gpio_conf), GFP_KERNEL);
	if (!sensordata->power_info.gpio_conf) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		rc = -ENOMEM;
		goto FREE_PS;
	}
	gconf = sensordata->power_info.gpio_conf;

	gpio_array_size = of_gpio_count(of_node);
	CDBG("%s gpio count %d\n", __func__, gpio_array_size);

	if (gpio_array_size) {
		gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
			GFP_KERNEL);
		if (!gpio_array) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto FREE_GPIO_CONF;
		}
		for (i = 0; i < gpio_array_size; i++) {
			gpio_array[i] = of_get_gpio(of_node, i);
			CDBG("%s gpio_array[%d] = %d\n", __func__, i,
				gpio_array[i]);
		}

		rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto FREE_GPIO_CONF;
		}

		rc = msm_camera_get_dt_gpio_set_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto FREE_GPIO_REQ_TBL;
		}

		rc = msm_camera_init_gpio_pin_tbl(of_node, gconf,
			gpio_array, gpio_array_size);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto FREE_GPIO_SET_TBL;
		}
	}
	rc = msm_sensor_get_dt_actuator_data(of_node,
					     &sensordata->actuator_info);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_GPIO_PIN_TBL;
	}

	sensordata->slave_info = kzalloc(sizeof(struct msm_camera_slave_info),
		GFP_KERNEL);
	if (!sensordata->slave_info) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		rc = -ENOMEM;
		goto FREE_ACTUATOR_INFO;
	}

	rc = of_property_read_u32_array(of_node, "qcom,slave-id",
		id_info, 3);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto FREE_SLAVE_INFO;
	}

	sensordata->slave_info->sensor_slave_addr = id_info[0];
	sensordata->slave_info->sensor_id_reg_addr = id_info[1];
	sensordata->slave_info->sensor_id = id_info[2];
	CDBG("%s:%d slave addr %x sensor reg %x id %x\n", __func__, __LINE__,
		sensordata->slave_info->sensor_slave_addr,
		sensordata->slave_info->sensor_id_reg_addr,
		sensordata->slave_info->sensor_id);

	/*Optional property, don't return error if absent */
	ret = of_property_read_string(of_node, "qcom,vdd-cx-name",
		&sensordata->misc_regulator);
	CDBG("%s qcom,misc_regulator %s, rc %d\n", __func__,
		 sensordata->misc_regulator, ret);

	kfree(gpio_array);

	return rc;

FREE_SLAVE_INFO:
	kfree(s_ctrl->sensordata->slave_info);
FREE_ACTUATOR_INFO:
	kfree(s_ctrl->sensordata->actuator_info);
FREE_GPIO_PIN_TBL:
	kfree(s_ctrl->sensordata->power_info.gpio_conf->gpio_num_info);
FREE_GPIO_SET_TBL:
	kfree(s_ctrl->sensordata->power_info.gpio_conf->cam_gpio_set_tbl);
FREE_GPIO_REQ_TBL:
	kfree(s_ctrl->sensordata->power_info.gpio_conf->cam_gpio_req_tbl);
FREE_GPIO_CONF:
	kfree(s_ctrl->sensordata->power_info.gpio_conf);
FREE_PS:
	kfree(s_ctrl->sensordata->power_info.power_setting);
	kfree(s_ctrl->sensordata->power_info.power_down_setting);
FREE_VREG:
	kfree(s_ctrl->sensordata->power_info.cam_vreg);
FREE_CSI:
	kfree(s_ctrl->sensordata->csi_lane_params);
FREE_SENSOR_INFO:
	kfree(s_ctrl->sensordata->sensor_info);
FREE_SENSORDATA:
	kfree(s_ctrl->sensordata);
	kfree(gpio_array);
	return rc;
}
static int32_t msm_sensor_driver_get_gpio_data(
	struct msm_camera_sensor_board_info *sensordata,
	struct device_node *of_node)
{
	int32_t                      rc = 0, i = 0;
	struct msm_camera_gpio_conf *gconf = NULL;
	uint16_t                    *gpio_array = NULL;
	uint16_t                     gpio_array_size = 0;

	/* Validate input paramters */
	if (!sensordata || !of_node) {
		pr_err("failed: invalid params sensordata %p of_node %p",
			sensordata, of_node);
		return -EINVAL;
	}

	sensordata->power_info.gpio_conf = kzalloc(
			sizeof(struct msm_camera_gpio_conf), GFP_KERNEL);
	if (!sensordata->power_info.gpio_conf) {
		pr_err("failed");
		return -ENOMEM;
	}
	gconf = sensordata->power_info.gpio_conf;

	gpio_array_size = of_gpio_count(of_node);
	CDBG("gpio count %d", gpio_array_size);
	if (!gpio_array_size)
		return 0;

	gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size, GFP_KERNEL);
	if (!gpio_array) {
		pr_err("failed");
		goto FREE_GPIO_CONF;
	}
	for (i = 0; i < gpio_array_size; i++) {
		gpio_array[i] = of_get_gpio(of_node, i);
		CDBG("gpio_array[%d] = %d", i, gpio_array[i]);
	}

	rc = msm_camera_get_dt_gpio_req_tbl(of_node, gconf, gpio_array,
		gpio_array_size);
	if (rc < 0) {
		pr_err("failed");
		goto FREE_GPIO_CONF;
	}

	rc = msm_camera_init_gpio_pin_tbl(of_node, gconf, gpio_array,
		gpio_array_size);
	if (rc < 0) {
		pr_err("failed");
		goto FREE_GPIO_REQ_TBL;
	}

	kfree(gpio_array);
	return rc;

FREE_GPIO_REQ_TBL:
	kfree(sensordata->power_info.gpio_conf->cam_gpio_req_tbl);
FREE_GPIO_CONF:
	kfree(sensordata->power_info.gpio_conf);
	kfree(gpio_array);
	return rc;
}
Exemplo n.º 26
0
static int s2mps13_pmic_dt_parse_pdata(struct sec_pmic_dev *iodev,
					struct sec_platform_data *pdata)
{
	struct device_node *pmic_np, *regulators_np, *reg_np;
	struct sec_regulator_data *rdata;
	unsigned int i, s2mps13_desc_type;
	int ret;
	u32 val;

	pmic_np = iodev->dev->of_node;
	if (!pmic_np) {
		dev_err(iodev->dev, "could not find pmic sub-node\n");
		return -ENODEV;
	}
	/* If pmic revision number over 0x02, get 3 gpio values */
	if (SEC_PMIC_REV(iodev) > 0x02) {
		if (of_gpio_count(pmic_np) < 3) {
			dev_err(iodev->dev, "could not find pmic gpios\n");
			return -EINVAL;
		}
		pdata->smpl_warn = of_get_gpio(pmic_np, 0);
		pdata->g3d_pin = of_get_gpio(pmic_np, 1);
		pdata->dvs_pin = of_get_gpio(pmic_np, 2);

		ret = of_property_read_u32(pmic_np, "g3d_en", &val);
		if (ret)
			return -EINVAL;
		pdata->g3d_en = !!val;

		ret = of_property_read_u32(pmic_np, "dvs_en", &val);
		if (ret)
			return -EINVAL;
		pdata->dvs_en = !!val;

		ret = of_property_read_u32(pmic_np, "smpl_warn_en", &val);
		if (ret)
			return -EINVAL;
		pdata->smpl_warn_en = !!val;
	} else {
		dev_err(iodev->dev, "cannot control g3d_en & dvs_en\n");
	}

	pdata->ap_buck_avp_en = false;
	pdata->sub_buck_avp_en = false;
	if (of_find_property(pmic_np, "ap-buck-avp-en", NULL))
		pdata->ap_buck_avp_en = true;

	if (of_find_property(pmic_np, "sub-buck-avp-en", NULL))
		pdata->sub_buck_avp_en = true;

	regulators_np = of_find_node_by_name(pmic_np, "regulators");
	if (!regulators_np) {
		dev_err(iodev->dev, "could not find regulators sub-node\n");
		return -EINVAL;
	}

	/* count the number of regulators to be supported in pmic */
	pdata->num_regulators = 0;
	for_each_child_of_node(regulators_np, reg_np) {
		pdata->num_regulators++;
	}

	rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
				pdata->num_regulators, GFP_KERNEL);
	if (!rdata) {
		dev_err(iodev->dev,
			"could not allocate memory for regulator data\n");
		return -ENOMEM;
	}

	pdata->regulators = rdata;
	s2mps13_desc_type = SEC_PMIC_REV(iodev) ? S2MPS13_DESC_TYPE1 : S2MPS13_DESC_TYPE0;
	for_each_child_of_node(regulators_np, reg_np) {
		for (i = 0; i < ARRAY_SIZE(regulators[s2mps13_desc_type]); i++)
			if (!of_node_cmp(reg_np->name,
					regulators[s2mps13_desc_type][i].name))
				break;

		if (i == ARRAY_SIZE(regulators[s2mps13_desc_type])) {
			dev_warn(iodev->dev,
			"don't know how to configure regulator %s\n",
			reg_np->name);
			continue;
		}

		rdata->id = i;
		rdata->initdata = of_get_regulator_init_data(
						iodev->dev, reg_np);
		rdata->reg_node = reg_np;
		rdata++;
	}

	return 0;
}
static int32_t msm_led_get_dt_data(struct device_node *of_node,
		struct msm_led_flash_ctrl_t *fctrl)
{
	int32_t rc = 0, i = 0;
	struct msm_camera_gpio_conf *gconf = NULL;
	struct device_node *flash_src_node = NULL;
	struct msm_camera_sensor_board_info *flashdata = NULL;
	uint32_t count = 0;
	uint16_t *gpio_array = NULL;
	uint16_t gpio_array_size = 0;
	uint32_t id_info[3];

	CDBG("called\n");

	if (!of_node) {
		pr_err("of_node NULL\n");
		return -EINVAL;
	}

	fctrl->flashdata = kzalloc(sizeof(
		struct msm_camera_sensor_board_info),
		GFP_KERNEL);
	if (!fctrl->flashdata) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}

	flashdata = fctrl->flashdata;

	flashdata->sensor_init_params = kzalloc(sizeof(
		struct msm_sensor_init_params), GFP_KERNEL);
	if (!flashdata->sensor_init_params) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		return -ENOMEM;
	}

	rc = of_property_read_u32(of_node, "cell-index", &fctrl->subdev_id);
	if (rc < 0) {
		pr_err("failed\n");
		return -EINVAL;
	}

	CDBG("subdev id %d\n", fctrl->subdev_id);

	rc = of_property_read_string(of_node, "qcom,flash-name",
		&flashdata->sensor_name);
	CDBG("%s qcom,flash-name %s, rc %d\n", __func__,
		flashdata->sensor_name, rc);
	if (rc < 0) {
		pr_err("%s failed %d\n", __func__, __LINE__);
		goto ERROR1;
	}

	rc = of_property_read_u32(of_node, "qcom,cci-master",
		&fctrl->cci_i2c_master);
	CDBG("%s qcom,cci-master %d, rc %d\n", __func__, fctrl->cci_i2c_master,
		rc);
	if (rc < 0) {
		/* Set default master 0 */
		fctrl->cci_i2c_master = MASTER_0;
		rc = 0;
	}

	if (of_get_property(of_node, "qcom,flash-source", &count)) {
		count /= sizeof(uint32_t);
		CDBG("count %d\n", count);
		if (count > MAX_LED_TRIGGERS) {
			pr_err("failed\n");
			return -EINVAL;
		}
		for (i = 0; i < count; i++) {
			flash_src_node = of_parse_phandle(of_node,
				"qcom,flash-source", i);
			if (!flash_src_node) {
				pr_err("flash_src_node NULL\n");
				continue;
			}

			rc = of_property_read_string(flash_src_node,
				"linux,default-trigger",
				&fctrl->flash_trigger_name[i]);
			if (rc < 0) {
				pr_err("failed\n");
				of_node_put(flash_src_node);
				continue;
			}

			CDBG("default trigger %s\n",
				 fctrl->flash_trigger_name[i]);

			rc = of_property_read_u32(flash_src_node,
				"qcom,max-current",
				&fctrl->flash_op_current[i]);
			if (rc < 0) {
				pr_err("failed rc %d\n", rc);
				of_node_put(flash_src_node);
				continue;
			}

			of_node_put(flash_src_node);

			CDBG("max_current[%d] %d\n",
				i, fctrl->flash_op_current[i]);

			led_trigger_register_simple(
				fctrl->flash_trigger_name[i],
				&fctrl->flash_trigger[i]);
		}

	} else { /*Handle LED Flash Ctrl by GPIO*/
		flashdata->gpio_conf =
			 kzalloc(sizeof(struct msm_camera_gpio_conf),
				 GFP_KERNEL);
		if (!flashdata->gpio_conf) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			return rc;
		}
		gconf = flashdata->gpio_conf;

		gpio_array_size = of_gpio_count(of_node);
		CDBG("%s gpio count %d\n", __func__, gpio_array_size);

		if (gpio_array_size) {
			gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size,
				GFP_KERNEL);
			if (!gpio_array) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				rc = -ENOMEM;
				goto ERROR4;
			}
			for (i = 0; i < gpio_array_size; i++) {
				gpio_array[i] = of_get_gpio(of_node, i);
				CDBG("%s gpio_array[%d] = %d\n", __func__, i,
					gpio_array[i]);
			}

			rc = msm_sensor_get_dt_gpio_req_tbl(of_node, gconf,
				gpio_array, gpio_array_size);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR4;
			}

			rc = msm_sensor_get_dt_gpio_set_tbl(of_node, gconf,
				gpio_array, gpio_array_size);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR5;
			}

			rc = msm_flash_init_gpio_pin_tbl(of_node, gconf,
				gpio_array, gpio_array_size, fctrl);
			if (rc < 0) {
				pr_err("%s failed %d\n", __func__, __LINE__);
				goto ERROR6;
			}
		}

		flashdata->slave_info =
			kzalloc(sizeof(struct msm_camera_slave_info),
				GFP_KERNEL);
		if (!flashdata->slave_info) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			rc = -ENOMEM;
			goto ERROR8;
		}

		rc = of_property_read_u32_array(of_node, "qcom,slave-id",
			id_info, 3);
		if (rc < 0) {
			pr_err("%s failed %d\n", __func__, __LINE__);
			goto ERROR9;
		}
		/* Fix me - Currently for I2c framework is looking for
		7-bit device node entry in dts. But the camera led framework
		for i2c slaves is looking for 8 bit address.So added a shift.
		Need to fix this.*/
		if (fctrl->flash_device_type == MSM_CAMERA_I2C_DEVICE) {
			fctrl->flashdata->slave_info->sensor_slave_addr =
			id_info[0] << 1;
		} else {
			fctrl->flashdata->slave_info->sensor_slave_addr
			 = id_info[0];
		}

		fctrl->flashdata->slave_info->sensor_id_reg_addr = id_info[1];
		fctrl->flashdata->slave_info->sensor_id = id_info[2];

		kfree(gpio_array);
		return rc;
ERROR9:
		kfree(fctrl->flashdata->slave_info);
ERROR8:
		kfree(fctrl->flashdata->gpio_conf->gpio_num_info);
ERROR6:
		kfree(gconf->cam_gpio_set_tbl);
ERROR5:
		kfree(gconf->cam_gpio_req_tbl);
ERROR4:
		kfree(gconf);
ERROR1:
		kfree(fctrl->flashdata);
		kfree(gpio_array);
	}
	return rc;
}