Exemple #1
0
int __init knxjif_init_i2c(void)
{
	struct i2c_adapter *adapter;
	int res;

	adapter = i2c_get_adapter(i2c_bus);

	if (!adapter) {
		pr_warn("knxjif: i2c_get_adapter(%d) failed\n", i2c_bus);
		goto fail;
	}

#ifdef USE_ACC_IRQ
	res = gpio_request(gpio_line, NAME);
	if (0 > res) {
		pr_warn("knxjif: request gpio failed\n");
		goto fail2;
	}

	res = gpio_direction_input(gpio_line);
	if (0 > res) {
		pr_warn("knxjif: gpio direction input failed\n");
		goto fail2;
	}

	knxjif_board_info.irq = gpio_to_irq(gpio_line);
#endif // #ifdef USE_ACC_IRQ

#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35)
	knxjif_i2c_client = i2c_new_probed_device(adapter,
			&knxjif_board_info,
			knxjif_addr_list,
			__knxjif_probe_i2c);
#else
	knxjif_i2c_client = i2c_new_probed_device(adapter,
			&knxjif_board_info,
			knxjif_addr_list);
#endif

	if (!knxjif_i2c_client) {
		pr_warn("knxjif: i2c_new_probed_device() failed\n");
		goto fail1;
	}

	i2c_put_adapter(adapter);

	return 0;

fail2:
#ifdef USE_ACC_IRQ
	gpio_free(gpio_line);
#endif	
fail1:
	i2c_put_adapter(adapter);
fail:
	return -1;
}
Exemple #2
0
int cx18_i2c_register(struct cx18 *cx, unsigned idx)
{
	struct i2c_board_info info;
	struct i2c_client *c;
	u8 id, bus;
	int i;

	CX18_DEBUG_I2C("i2c client register\n");
	if (idx >= ARRAY_SIZE(hw_driverids) || hw_driverids[idx] == 0)
		return -1;
	id = hw_driverids[idx];
	bus = hw_bus[idx];
	memset(&info, 0, sizeof(info));
	strlcpy(info.type, hw_devicenames[idx], sizeof(info.type));
	info.addr = hw_addrs[idx];
	for (i = 0; i < I2C_CLIENTS_MAX; i++)
		if (cx->i2c_clients[i] == NULL)
			break;

	if (i == I2C_CLIENTS_MAX) {
		CX18_ERR("insufficient room for new I2C client!\n");
		return -ENOMEM;
	}

	if (id != I2C_DRIVERID_TUNER) {
		c = i2c_new_device(&cx->i2c_adap[bus], &info);
		if (c->driver == NULL)
			i2c_unregister_device(c);
		else
			cx->i2c_clients[i] = c;
		return cx->i2c_clients[i] ? 0 : -ENODEV;
	}

	/* special tuner handling */
	c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->radio);
	if (c && c->driver == NULL)
		i2c_unregister_device(c);
	else if (c)
		cx->i2c_clients[i++] = c;
	c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->demod);
	if (c && c->driver == NULL)
		i2c_unregister_device(c);
	else if (c)
		cx->i2c_clients[i++] = c;
	c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->tv);
	if (c && c->driver == NULL)
		i2c_unregister_device(c);
	else if (c)
		cx->i2c_clients[i++] = c;
	return 0;
}
Exemple #3
0
void init_bttv_i2c_ir(struct bttv *btv)
#endif
{
	const unsigned short addr_list[] = {
		0x1a, 0x18, 0x64, 0x30, 0x71,
		I2C_CLIENT_END
	};
	struct i2c_board_info info;

	if (0 != btv->i2c_rc)
		return;

	memset(&info, 0, sizeof(struct i2c_board_info));
	memset(&btv->init_data, 0, sizeof(btv->init_data));
	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);

	switch (btv->c.type) {
	case BTTV_BOARD_PV951:
		btv->init_data.name = "PV951";
		btv->init_data.get_key = get_key_pv951;
		btv->init_data.ir_codes = RC_MAP_PV951;
		info.addr = 0x4b;
		break;
	default:
		/*
		 * The external IR receiver is at i2c address 0x34 (0x35 for
		 * reads).  Future Hauppauge cards will have an internal
		 * receiver at 0x30 (0x31 for reads).  In theory, both can be
		 * fitted, and Hauppauge suggest an external overrides an
		 * internal.
		 * That's why we probe 0x1a (~0x34) first. CB
		 */
		 
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
		i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list);
#else
		i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
#endif
		
		return;
	}

	if (btv->init_data.name)
		info.platform_data = &btv->init_data;
	i2c_new_device(&btv->c.i2c_adap, &info);

	return;
}
Exemple #4
0
/* Load an i2c sub-device. */
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
		struct i2c_adapter *adapter, struct i2c_board_info *info,
		const unsigned short *probe_addrs)
{
	struct v4l2_subdev *sd = NULL;
	struct i2c_client *client;

	BUG_ON(!v4l2_dev);

	request_module(I2C_MODULE_PREFIX "%s", info->type);

	/* Create the i2c client */
	if (info->addr == 0 && probe_addrs)
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,35)
		client = i2c_new_probed_device(adapter, info, probe_addrs);
#else
		client = i2c_new_probed_device(adapter, info, probe_addrs,
								 NULL);
#endif
	else
Exemple #5
0
/* init + register i2c algo-bit adapter */
int cx23885_i2c_register(struct cx23885_i2c *bus)
{
	struct cx23885_dev *dev = bus->dev;

	dprintk(1, "%s(bus = %d)\n", __func__, bus->nr);

	memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template,
	       sizeof(bus->i2c_adap));
	memcpy(&bus->i2c_algo, &cx23885_i2c_algo_template,
	       sizeof(bus->i2c_algo));
	memcpy(&bus->i2c_client, &cx23885_i2c_client_template,
	       sizeof(bus->i2c_client));

	bus->i2c_adap.dev.parent = &dev->pci->dev;

	strlcpy(bus->i2c_adap.name, bus->dev->name,
		sizeof(bus->i2c_adap.name));

	bus->i2c_algo.data = bus;
	bus->i2c_adap.algo_data = bus;
	i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
	i2c_add_adapter(&bus->i2c_adap);

	bus->i2c_client.adapter = &bus->i2c_adap;

	if (0 == bus->i2c_rc) {
		dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr);
		if (i2c_scan) {
			printk(KERN_INFO "%s: scan bus %d:\n",
					dev->name, bus->nr);
			do_i2c_scan(dev->name, &bus->i2c_client);
		}
	} else
		printk(KERN_WARNING "%s: i2c bus %d register FAILED\n",
			dev->name, bus->nr);

	/* Instantiate the IR receiver device, if present */
	if (0 == bus->i2c_rc) {
		struct i2c_board_info info;
		const unsigned short addr_list[] = {
			0x6b, I2C_CLIENT_END
		};

		memset(&info, 0, sizeof(struct i2c_board_info));
		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
		/* Use quick read command for probe, some IR chips don't
		 * support writes */
		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
				      i2c_probe_func_quick_read);
	}

	return bus->i2c_rc;
}
Exemple #6
0
static struct i2c_client __init *__add_probed_i2c_device(
		const char *name,
		int bus,
		struct i2c_board_info *info,
		const unsigned short *addrs)
{
	const struct dmi_device *dmi_dev;
	const struct dmi_dev_onboard *dev_data;
	struct i2c_adapter *adapter;
	struct i2c_client *client;

	if (bus < 0)
		return NULL;
	/*
	 * If a name is specified, look for irq platform information stashed
	 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
	 */
	if (name) {
		dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
		if (!dmi_dev) {
			pr_err("%s failed to dmi find device %s.\n",
			       __func__,
			       name);
			return NULL;
		}
		dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
		if (!dev_data) {
			pr_err("%s failed to get data from dmi for %s.\n",
			       __func__, name);
			return NULL;
		}
		info->irq = dev_data->instance;
	}

	adapter = i2c_get_adapter(bus);
	if (!adapter) {
		pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
		return NULL;
	}

	/* add the i2c device */
	client = i2c_new_probed_device(adapter, info, addrs, NULL);
	if (!client)
		pr_err("%s failed to register device %d-%02x\n",
		       __func__, bus, info->addr);
	else
		pr_debug("%s added i2c device %d-%02x\n",
			 __func__, bus, info->addr);

	i2c_put_adapter(adapter);
	return client;
}
/* Load an i2c sub-device. */
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
		struct i2c_adapter *adapter, struct i2c_board_info *info,
		const unsigned short *probe_addrs)
{
	struct v4l2_subdev *sd = NULL;
	struct i2c_client *client;

	BUG_ON(!v4l2_dev);

	request_module(I2C_MODULE_PREFIX "%s", info->type);

	/* Create the i2c client */
	if (info->addr == 0 && probe_addrs)
		client = i2c_new_probed_device(adapter, info, probe_addrs,
					       NULL);
	else
		client = i2c_new_device(adapter, info);

	/* Note: by loading the module first we are certain that c->driver
	   will be set if the driver was found. If the module was not loaded
	   first, then the i2c core tries to delay-load the module for us,
	   and then c->driver is still NULL until the module is finally
	   loaded. This delay-load mechanism doesn't work if other drivers
	   want to use the i2c device, so explicitly loading the module
	   is the best alternative. */
	if (client == NULL || client->driver == NULL)
		goto error;

	/* Lock the module so we can safely get the v4l2_subdev pointer */
	if (!try_module_get(client->driver->driver.owner))
		goto error;
	sd = i2c_get_clientdata(client);

	/* Register with the v4l2_device which increases the module's
	   use count as well. */
	if (v4l2_device_register_subdev(v4l2_dev, sd))
		sd = NULL;
	/* Decrease the module use count to match the first try_module_get. */
	module_put(client->driver->driver.owner);

error:
	/* If we have a client but no subdev, then something went wrong and
	   we must unregister the client. */
	if (client && sd == NULL)
		i2c_unregister_device(client);
	return sd;
}
Exemple #8
0
/* Instantiate the I2C IR receiver device, if present */
void init_bttv_i2c_ir(struct bttv *btv)
{
	const unsigned short addr_list[] = {
		0x1a, 0x18, 0x64, 0x30, 0x71,
		I2C_CLIENT_END
	};
	struct i2c_board_info info;
	struct i2c_client *i2c_dev;

	if (0 != btv->i2c_rc)
		return;

	memset(&info, 0, sizeof(struct i2c_board_info));
	memset(&btv->init_data, 0, sizeof(btv->init_data));
	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);

	switch (btv->c.type) {
	case BTTV_BOARD_PV951:
		btv->init_data.name = "PV951";
		btv->init_data.get_key = get_key_pv951;
		btv->init_data.ir_codes = RC_MAP_PV951;
		info.addr = 0x4b;
		break;
	}

	if (btv->init_data.name) {
		info.platform_data = &btv->init_data;
		i2c_dev = i2c_new_device(&btv->c.i2c_adap, &info);
	} else {
		/*
		 * The external IR receiver is at i2c address 0x34 (0x35 for
		 * reads).  Future Hauppauge cards will have an internal
		 * receiver at 0x30 (0x31 for reads).  In theory, both can be
		 * fitted, and Hauppauge suggest an external overrides an
		 * internal.
		 * That's why we probe 0x1a (~0x34) first. CB
		 */
		i2c_dev = i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
	}
	if (NULL == i2c_dev)
		return;

#if defined(CONFIG_MODULES) && defined(MODULE)
	request_module("ir-kbd-i2c");
#endif
}
Exemple #9
0
void cx88_i2c_init_ir(struct cx88_core *core)
{
	/* Instantiate the IR receiver device, if present */
	if (0 == core->i2c_rc) {
		struct i2c_board_info info;
		const unsigned short addr_list[] = {
			0x18, 0x6b, 0x71,
			I2C_CLIENT_END
		};

		memset(&info, 0, sizeof(struct i2c_board_info));
		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
		/* Use quick read command for probe, some IR chips don't
		 * support writes */
		i2c_new_probed_device(&core->i2c_adap, &info, addr_list,
				      i2c_probe_func_quick_read);
	}
}
/* Instantiate the I2C IR receiver device, if present */
void __devinit init_bttv_i2c_ir(struct bttv *btv)
{
	if (0 == btv->i2c_rc) {
		struct i2c_board_info info;
		/* The external IR receiver is at i2c address 0x34 (0x35 for
		   reads).  Future Hauppauge cards will have an internal
		   receiver at 0x30 (0x31 for reads).  In theory, both can be
		   fitted, and Hauppauge suggest an external overrides an
		   internal.

		   That's why we probe 0x1a (~0x34) first. CB
		*/
		const unsigned short addr_list[] = {
			0x1a, 0x18, 0x4b, 0x64, 0x30, 0x71,
			I2C_CLIENT_END
		};

		memset(&info, 0, sizeof(struct i2c_board_info));
		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
		i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list);
	}
}
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
		struct i2c_adapter *adapter, struct i2c_board_info *info,
		const unsigned short *probe_addrs)
{
	struct v4l2_subdev *sd = NULL;
	struct i2c_client *client;

	BUG_ON(!v4l2_dev);

	request_module(I2C_MODULE_PREFIX "%s", info->type);

	
	if (info->addr == 0 && probe_addrs)
		client = i2c_new_probed_device(adapter, info, probe_addrs,
					       NULL);
	else
		client = i2c_new_device(adapter, info);

	if (client == NULL || client->driver == NULL)
		goto error;

	
	if (!try_module_get(client->driver->driver.owner))
		goto error;
	sd = i2c_get_clientdata(client);

	if (v4l2_device_register_subdev(v4l2_dev, sd))
		sd = NULL;
	
	module_put(client->driver->driver.owner);

error:
	if (client && sd == NULL)
		i2c_unregister_device(client);
	return sd;
}
Exemple #12
0
static int __devinit smsc_hub_probe(struct platform_device *pdev)
{
	int ret = 0;
	const struct smsc_hub_platform_data *pdata;
	struct device_node *node = pdev->dev.of_node;
	struct i2c_adapter *i2c_adap;
	struct i2c_board_info i2c_info;

	if (pdev->dev.of_node) {
		dev_dbg(&pdev->dev, "device tree enabled\n");
		pdev->dev.platform_data = msm_hub_dt_to_pdata(pdev);
		if (IS_ERR(pdev->dev.platform_data))
			return PTR_ERR(pdev->dev.platform_data);

		dev_set_name(&pdev->dev, smsc_hub_driver.driver.name);
	}

	if (!pdev->dev.platform_data) {
		dev_err(&pdev->dev, "No platform data\n");
		return -ENODEV;
	}

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

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

	smsc_hub->dev = &pdev->dev;
	smsc_hub->pdata = pdev->dev.platform_data;

	smsc_hub->hub_vbus_reg = devm_regulator_get(&pdev->dev, "hub_vbus");
	ret = PTR_ERR(smsc_hub->hub_vbus_reg);
	if (ret == -EPROBE_DEFER) {
		dev_dbg(&pdev->dev, "failed to get hub_vbus\n");
		return ret;
	}

	ret = msm_hsic_hub_init_vdd(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub VDD\n");
		return ret;
	}
	ret = msm_hsic_hub_init_clock(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub clock\n");
		goto uninit_vdd;
	}
	ret = msm_hsic_hub_init_gpio(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub gpios\n");
		goto uninit_clock;
	}

	gpio_direction_output(pdata->hub_reset, 0);
	/* Hub reset should be asserted for minimum 2microsec
	 * before deasserting.
	 */
	udelay(5);
	gpio_direction_output(pdata->hub_reset, 1);

	ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "failed to add child node, ret=%d\n", ret);
		goto uninit_gpio;
	}

	if (!IS_ERR(smsc_hub->hub_vbus_reg)) {
		ret = regulator_enable(smsc_hub->hub_vbus_reg);
		if (ret) {
			dev_err(&pdev->dev, "unable to enable hub_vbus\n");
			goto uninit_gpio;
		}
	}

	ret = i2c_add_driver(&hsic_hub_driver);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to add I2C hsic_hub_driver\n");
		goto i2c_add_fail;
	}
	usleep_range(10000, 12000);
	i2c_adap = i2c_get_adapter(SMSC_GSBI_I2C_BUS_ID);

	if (!i2c_adap) {
		dev_err(&pdev->dev, "failed to get i2c adapter\n");
		i2c_del_driver(&hsic_hub_driver);
		goto i2c_add_fail;
	}

	memset(&i2c_info, 0, sizeof(struct i2c_board_info));
	strlcpy(i2c_info.type, "i2c_hsic_hub", I2C_NAME_SIZE);

	smsc_hub->client = i2c_new_probed_device(i2c_adap, &i2c_info,
						   normal_i2c, NULL);
	i2c_put_adapter(i2c_adap);
	if (!smsc_hub->client)
		dev_err(&pdev->dev, "failed to connect to smsc_hub"
			 "through I2C\n");

i2c_add_fail:
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

uninit_gpio:
	msm_hsic_hub_init_gpio(smsc_hub, 0);
uninit_clock:
	msm_hsic_hub_init_clock(smsc_hub, 0);
uninit_vdd:
	msm_hsic_hub_init_vdd(smsc_hub, 0);

	return ret;
}
Exemple #13
0
static int __devinit smsc_hub_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct smsc_hub_platform_data *pdata;
	struct device_node *node = pdev->dev.of_node;
	struct i2c_adapter *i2c_adap;
	struct i2c_board_info i2c_info;
	struct of_dev_auxdata *hsic_host_auxdata = NULL;

	if (pdev->dev.of_node) {
		dev_dbg(&pdev->dev, "device tree enabled\n");
		pdata = msm_hub_dt_to_pdata(pdev);
		if (IS_ERR(pdata))
			return PTR_ERR(pdata);
	} else {
		pdata = pdev->dev.platform_data;
	}
	hsic_host_auxdata = dev_get_platdata(&pdev->dev);

	if (!pdata) {
		dev_err(&pdev->dev, "No platform data\n");
		return -ENODEV;
	}

	if (pdata->model_id == 0) {
		dev_dbg(&pdev->dev, "standalone HSIC config enabled\n");
		return of_platform_populate(node, NULL,
				hsic_host_auxdata, &pdev->dev);
	}

	if (!pdata->hub_reset)
		return -EINVAL;

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

	smsc_hub->dev = &pdev->dev;
	smsc_hub->pdata = pdata;

	if (of_get_property(pdev->dev.of_node, "hub-vbus-supply", NULL)) {
		smsc_hub->hub_vbus_reg = devm_regulator_get(&pdev->dev,
				"hub-vbus");
		ret = PTR_ERR(smsc_hub->hub_vbus_reg);
		if (ret == -EPROBE_DEFER) {
			dev_dbg(&pdev->dev, "failed to get hub_vbus\n");
			return ret;
		}
	}

	ret = msm_hsic_hub_init_vdd(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub VDD\n");
		return ret;
	}
	ret = msm_hsic_hub_init_clock(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub clock\n");
		goto uninit_vdd;
	}
	ret = msm_hsic_hub_init_gpio(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub gpios\n");
		goto uninit_clock;
	}

	if (pdata->model_id == SMSC3502_ID) {
		ret = device_create_file(&pdev->dev, &dev_attr_enable);
		if (ret < 0) {
			dev_err(&pdev->dev, "fail to create sysfs file\n");
			goto uninit_gpio;
		}
		pm_runtime_forbid(&pdev->dev);
		goto done;
	}

	gpio_direction_output(pdata->hub_reset, 0);
	udelay(5);
	gpio_direction_output(pdata->hub_reset, 1);

	if (!IS_ERR_OR_NULL(smsc_hub->hub_vbus_reg)) {
		ret = regulator_enable(smsc_hub->hub_vbus_reg);
		if (ret) {
			dev_err(&pdev->dev, "unable to enable hub_vbus\n");
			goto uninit_gpio;
		}
	}

	ret = i2c_add_driver(&hsic_hub_driver);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to add I2C hsic_hub_driver\n");
		goto i2c_add_fail;
	}
	usleep_range(10000, 12000);
	i2c_adap = i2c_get_adapter(SMSC_GSBI_I2C_BUS_ID);

	if (!i2c_adap) {
		dev_err(&pdev->dev, "failed to get i2c adapter\n");
		i2c_del_driver(&hsic_hub_driver);
		goto i2c_add_fail;
	}

	memset(&i2c_info, 0, sizeof(struct i2c_board_info));
	strlcpy(i2c_info.type, "i2c_hsic_hub", I2C_NAME_SIZE);

	
	msleep(250);

	
	switch (pdata->model_id) {
	case SMSC3503_ID:
		normal_i2c[0] = SMSC3503_I2C_ADDR;
		break;
	case SMSC4604_ID:
		normal_i2c[0] = SMSC4604_I2C_ADDR;
		break;
	default:
		dev_err(&pdev->dev, "unsupported SMSC model-id\n");
		i2c_put_adapter(i2c_adap);
		i2c_del_driver(&hsic_hub_driver);
		goto uninit_gpio;
	}

	smsc_hub->client = i2c_new_probed_device(i2c_adap, &i2c_info,
						   normal_i2c, NULL);
	i2c_put_adapter(i2c_adap);

i2c_add_fail:
	ret = of_platform_populate(node, NULL, hsic_host_auxdata, &pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "failed to add child node, ret=%d\n", ret);
		goto uninit_gpio;
	}

	smsc_hub->enabled = true;

	if (!smsc_hub->client)
		dev_err(&pdev->dev,
			"failed to connect to smsc_hub through I2C\n");

done:
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

uninit_gpio:
	msm_hsic_hub_init_gpio(smsc_hub, 0);
uninit_clock:
	msm_hsic_hub_init_clock(smsc_hub, 0);
uninit_vdd:
	msm_hsic_hub_init_vdd(smsc_hub, 0);

	return ret;
}
Exemple #14
0
static int __devinit smsc_hub_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct smsc_hub_platform_data *pdata;
	struct device_node *node = pdev->dev.of_node;
	struct i2c_adapter *i2c_adap;
	struct i2c_board_info i2c_info;
	struct of_dev_auxdata *hsic_host_auxdata = NULL;

	if (pdev->dev.of_node) {
		dev_dbg(&pdev->dev, "device tree enabled\n");
		hsic_host_auxdata = dev_get_platdata(&pdev->dev);
		pdata = msm_hub_dt_to_pdata(pdev);
		if (IS_ERR(pdata))
			return PTR_ERR(pdata);
	} else {
		pdata = pdev->dev.platform_data;
	}

	if (!pdata) {
		dev_err(&pdev->dev, "No platform data\n");
		return -ENODEV;
	}

	if (!pdata->hub_reset)
		return -EINVAL;

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

	smsc_hub->dev = &pdev->dev;
	smsc_hub->pdata = pdata;

	smsc_hub->hub_vbus_reg = devm_regulator_get(&pdev->dev, "hub_vbus");
	ret = PTR_ERR(smsc_hub->hub_vbus_reg);
	if (ret == -EPROBE_DEFER) {
		dev_dbg(&pdev->dev, "failed to get hub_vbus\n");
		return ret;
	}

	ret = msm_hsic_hub_init_vdd(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub VDD\n");
		return ret;
	}
	ret = msm_hsic_hub_init_clock(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub clock\n");
		goto uninit_vdd;
	}
	ret = msm_hsic_hub_init_gpio(smsc_hub, 1);
	if (ret) {
		dev_err(&pdev->dev, "failed to init hub gpios\n");
		goto uninit_clock;
	}

	gpio_direction_output(pdata->hub_reset, 0);
	/*
	 * Hub reset should be asserted for minimum 2microsec
	 * before deasserting.
	 */
	udelay(5);
	gpio_direction_output(pdata->hub_reset, 1);

	if (!IS_ERR(smsc_hub->hub_vbus_reg)) {
		ret = regulator_enable(smsc_hub->hub_vbus_reg);
		if (ret) {
			dev_err(&pdev->dev, "unable to enable hub_vbus\n");
			goto uninit_gpio;
		}
	}

	ret = i2c_add_driver(&hsic_hub_driver);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to add I2C hsic_hub_driver\n");
		goto i2c_add_fail;
	}
	usleep_range(10000, 12000);
	i2c_adap = i2c_get_adapter(SMSC_GSBI_I2C_BUS_ID);

	if (!i2c_adap) {
		dev_err(&pdev->dev, "failed to get i2c adapter\n");
		i2c_del_driver(&hsic_hub_driver);
		goto i2c_add_fail;
	}

	memset(&i2c_info, 0, sizeof(struct i2c_board_info));
	strlcpy(i2c_info.type, "i2c_hsic_hub", I2C_NAME_SIZE);

	/* 250ms delay is required for SMSC4604 HUB to get I2C up */
	msleep(250);

	/* Assign I2C slave address per SMSC model */
	switch (pdata->model_id) {
	case SMSC3503_ID:
		normal_i2c[0] = SMSC3503_I2C_ADDR;
		break;
	case SMSC4604_ID:
		normal_i2c[0] = SMSC4604_I2C_ADDR;
		break;
	default:
		dev_err(&pdev->dev, "unsupported SMSC model-id\n");
		i2c_put_adapter(i2c_adap);
		i2c_del_driver(&hsic_hub_driver);
		goto uninit_gpio;
	}

	smsc_hub->client = i2c_new_probed_device(i2c_adap, &i2c_info,
						   normal_i2c, NULL);
	i2c_put_adapter(i2c_adap);

i2c_add_fail:
	ret = of_platform_populate(node, NULL, hsic_host_auxdata, &pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "failed to add child node, ret=%d\n", ret);
		goto uninit_gpio;
	}

	if (!smsc_hub->client)
		dev_err(&pdev->dev,
			"failed to connect to smsc_hub through I2C\n");

	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

uninit_gpio:
	msm_hsic_hub_init_gpio(smsc_hub, 0);
uninit_clock:
	msm_hsic_hub_init_clock(smsc_hub, 0);
uninit_vdd:
	msm_hsic_hub_init_vdd(smsc_hub, 0);

	return ret;
}
	/* CONFIG_N bit in SP_ILOCK register has to be cleared for new
	 * values in registers to be effective after writing to
	 * other registers.
	 */
	hsic_hub_clear_bits(client, SMSC3503_SP_ILOCK, CONFIG_N);

	return 0;
}

static int i2c_hsic_hub_remove(struct i2c_client *client)
{
	return 0;
}

static const struct i2c_device_id hsic_hub_id[] = {
	{"i2c_hsic_hub", 0},
	{}
};
MODULE_DEVICE_TABLE(i2c, hsichub_id);

static struct i2c_driver hsic_hub_driver = {
	.driver = {
		.name = "i2c_hsic_hub",
	},
	.probe    = i2c_hsic_hub_probe,
	.remove   = i2c_hsic_hub_remove,
	.id_table = hsic_hub_id,
};

#define HSIC_HUB_VDD_VOL_MIN	1650000 /* uV */
#define HSIC_HUB_VDD_VOL_MAX	1950000 /* uV */
#define HSIC_HUB_VDD_LOAD	36000	/* uA */
static int __devinit smsc_hub_probe(struct platform_device *pdev)
{
	int ret = 0;
	const struct smsc_hub_platform_data *pdata;
	struct i2c_adapter *i2c_adap;
	struct i2c_board_info i2c_info;

	if (!pdev->dev.platform_data) {
		dev_err(&pdev->dev, "No platform data\n");
		return -ENODEV;
	}

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

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

	smsc_hub->hsic_hub_reg = regulator_get(&pdev->dev, "EXT_HUB_VDDIO");
	if (IS_ERR(smsc_hub->hsic_hub_reg)) {
		dev_err(&pdev->dev, "unable to get ext hub vddcx\n");
		ret = PTR_ERR(smsc_hub->hsic_hub_reg);
		goto free_mem;
	}

	ret = gpio_request(pdata->hub_reset, "HSIC_HUB_RESET_GPIO");
	if (ret < 0) {
		dev_err(&pdev->dev, "gpio request failed for GPIO%d\n",
							pdata->hub_reset);
		goto gpio_req_fail;
	}

	ret = regulator_set_voltage(smsc_hub->hsic_hub_reg,
			HSIC_HUB_VDD_VOL_MIN,
			HSIC_HUB_VDD_VOL_MAX);
	if (ret) {
		dev_err(&pdev->dev, "unable to set the voltage"
				"for hsic hub reg\n");
		goto reg_set_voltage_fail;
	}

	ret = regulator_set_optimum_mode(smsc_hub->hsic_hub_reg,
				HSIC_HUB_VDD_LOAD);
	if (ret < 0) {
		dev_err(&pdev->dev, "Unable to set optimum mode of regulator:"
							"VDDCX\n");
		goto reg_optimum_mode_fail;
	}

	ret = regulator_enable(smsc_hub->hsic_hub_reg);
	if (ret) {
		dev_err(&pdev->dev, "unable to enable ext hub vddcx\n");
		goto reg_enable_fail;
	}

	smsc_hub->xo_handle = msm_xo_get(MSM_XO_TCXO_D1, "hsic_hub");
	if (IS_ERR(smsc_hub->xo_handle)) {
		dev_err(&pdev->dev, "not able to get the handle"
					 "for TCXO D1 buffer\n");
			goto disable_regulator;
	}

	ret = msm_xo_mode_vote(smsc_hub->xo_handle, MSM_XO_MODE_ON);
	if (ret) {
		dev_err(&pdev->dev, "failed to vote for TCXO"
			"D1 buffer\n");
		goto xo_vote_fail;
	}

	gpio_direction_output(pdata->hub_reset, 0);
	/* Hub reset should be asserted for minimum 2microsec
	 * before deasserting.
	 */
	udelay(5);
	gpio_direction_output(pdata->hub_reset, 1);

	ret = i2c_add_driver(&hsic_hub_driver);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to add I2C hsic_hub_driver\n");
		goto i2c_add_fail;
	}
	usleep_range(10000, 12000);
	i2c_adap = i2c_get_adapter(SMSC_GSBI_I2C_BUS_ID);

	if (!i2c_adap) {
		dev_err(&pdev->dev, "failed to get i2c adapter\n");
		i2c_del_driver(&hsic_hub_driver);
		goto i2c_add_fail;
	}

	memset(&i2c_info, 0, sizeof(struct i2c_board_info));
	strlcpy(i2c_info.type, "i2c_hsic_hub", I2C_NAME_SIZE);

	smsc_hub->client = i2c_new_probed_device(i2c_adap, &i2c_info,
						   normal_i2c, NULL);
	i2c_put_adapter(i2c_adap);
	if (!smsc_hub->client)
		dev_err(&pdev->dev, "failed to connect to smsc_hub"
			 "through I2C\n");

i2c_add_fail:
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	return 0;

xo_vote_fail:
	msm_xo_put(smsc_hub->xo_handle);
disable_regulator:
	regulator_disable(smsc_hub->hsic_hub_reg);
reg_enable_fail:
	regulator_set_optimum_mode(smsc_hub->hsic_hub_reg, 0);
reg_optimum_mode_fail:
	regulator_set_voltage(smsc_hub->hsic_hub_reg, 0,
				HSIC_HUB_VDD_VOL_MIN);
reg_set_voltage_fail:
	gpio_free(pdata->hub_reset);
gpio_req_fail:
	regulator_put(smsc_hub->hsic_hub_reg);
free_mem:
	kfree(smsc_hub);

	return ret;
}
Exemple #16
0
int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
{
	
	if (i2c_udelay<5)
		i2c_udelay=5;

	memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
	       sizeof(core->i2c_algo));


	core->i2c_adap.dev.parent = &pci->dev;
	strlcpy(core->i2c_adap.name,core->name,sizeof(core->i2c_adap.name));
	core->i2c_adap.owner = THIS_MODULE;
	core->i2c_adap.id = I2C_HW_B_CX2388x;
	core->i2c_algo.udelay = i2c_udelay;
	core->i2c_algo.data = core;
	i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
	core->i2c_adap.algo_data = &core->i2c_algo;
	core->i2c_client.adapter = &core->i2c_adap;
	strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);

	cx8800_bit_setscl(core,1);
	cx8800_bit_setsda(core,1);

	core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap);
	if (0 == core->i2c_rc) {
		static u8 tuner_data[] =
			{ 0x0b, 0xdc, 0x86, 0x52 };
		static struct i2c_msg tuner_msg =
			{ .flags = 0, .addr = 0xc2 >> 1, .buf = tuner_data, .len = 4 };

		dprintk(1, "i2c register ok\n");
		switch( core->boardnr ) {
			case CX88_BOARD_HAUPPAUGE_HVR1300:
			case CX88_BOARD_HAUPPAUGE_HVR3000:
			case CX88_BOARD_HAUPPAUGE_HVR4000:
				printk("%s: i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n",
					core->name);
				i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1);
				break;
			default:
				break;
		}
		if (i2c_scan)
			do_i2c_scan(core->name,&core->i2c_client);
	} else
		printk("%s: i2c register FAILED\n", core->name);

	
	if (0 == core->i2c_rc) {
		struct i2c_board_info info;
		const unsigned short addr_list[] = {
			0x18, 0x6b, 0x71,
			I2C_CLIENT_END
		};

		memset(&info, 0, sizeof(struct i2c_board_info));
		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
		i2c_new_probed_device(&core->i2c_adap, &info, addr_list);
	}
	return core->i2c_rc;
}
Exemple #17
0
/* init + register i2c algo-bit adapter */
int cx23885_i2c_register(struct cx23885_i2c *bus)
{
	struct cx23885_dev *dev = bus->dev;

	dprintk(1, "%s(bus = %d)\n", __func__, bus->nr);

	memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template,
	       sizeof(bus->i2c_adap));
	memcpy(&bus->i2c_algo, &cx23885_i2c_algo_template,
	       sizeof(bus->i2c_algo));
	memcpy(&bus->i2c_client, &cx23885_i2c_client_template,
	       sizeof(bus->i2c_client));

	bus->i2c_adap.dev.parent = &dev->pci->dev;

	strlcpy(bus->i2c_adap.name, bus->dev->name,
		sizeof(bus->i2c_adap.name));

	bus->i2c_algo.data = bus;
	bus->i2c_adap.algo_data = bus;
	i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
	i2c_add_adapter(&bus->i2c_adap);

	bus->i2c_client.adapter = &bus->i2c_adap;

	if (0 == bus->i2c_rc) {
		dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr);
		if (i2c_scan) {
			printk(KERN_INFO "%s: scan bus %d:\n",
					dev->name, bus->nr);
			do_i2c_scan(dev->name, &bus->i2c_client);
		}
	} else
		printk(KERN_WARNING "%s: i2c bus %d register FAILED\n",
			dev->name, bus->nr);

	/* Instantiate the IR receiver device, if present */
	if (0 == bus->i2c_rc) {
		struct i2c_board_info info;
		const unsigned short addr_list[] = {
			0x6b, I2C_CLIENT_END
		};

		memset(&info, 0, sizeof(struct i2c_board_info));
		strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
		/* Use quick read command for probe, some IR chips don't
		 * support writes */
		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
				      i2c_probe_func_quick_read);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)			 
		/*
		 * We can't call i2c_new_probed_device() because it uses
		 * quick writes for probing and the IR receiver device only
		 * replies to reads.
		 */
		if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0,
				   I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK,
				   NULL) >= 0) {
			info.addr = addr_list[0];
			i2c_new_device(&bus->i2c_adap, &info);
		}
#endif
#endif
	}

	return bus->i2c_rc;
}
Exemple #18
0
static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
{
    struct usb_hcd *hcd = 0;
    struct ohci_hcd *ohci;
    const struct hc_driver *driver = &ohci_pnx4008_hc_driver;
    struct i2c_adapter *i2c_adap;
    struct i2c_board_info i2c_info;

    int ret = 0, irq;

    dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (pnx4008)\n", hcd_name);
    if (usb_disabled()) {
        err("USB is disabled");
        ret = -ENODEV;
        goto out;
    }

    if (pdev->num_resources != 2
            || pdev->resource[0].flags != IORESOURCE_MEM
            || pdev->resource[1].flags != IORESOURCE_IRQ) {
        err("Invalid resource configuration");
        ret = -ENODEV;
        goto out;
    }

    /* Enable AHB slave USB clock, needed for further USB clock control */
    __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL);

    ret = i2c_add_driver(&isp1301_driver);
    if (ret < 0) {
        err("failed to add ISP1301 driver");
        goto out;
    }
    i2c_adap = i2c_get_adapter(2);
    memset(&i2c_info, 0, sizeof(struct i2c_board_info));
    strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
    isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
                         normal_i2c, NULL);
    i2c_put_adapter(i2c_adap);
    if (!isp1301_i2c_client) {
        err("failed to connect I2C to ISP1301 USB Transceiver");
        ret = -ENODEV;
        goto out_i2c_driver;
    }

    isp1301_configure();

    /* Enable USB PLL */
    usb_clk = clk_get(&pdev->dev, "ck_pll5");
    if (IS_ERR(usb_clk)) {
        err("failed to acquire USB PLL");
        ret = PTR_ERR(usb_clk);
        goto out1;
    }

    ret = clk_enable(usb_clk);
    if (ret < 0) {
        err("failed to start USB PLL");
        goto out2;
    }

    ret = clk_set_rate(usb_clk, 48000);
    if (ret < 0) {
        err("failed to set USB clock rate");
        goto out3;
    }

    __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);

    /* Set to enable all needed USB clocks */
    __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL);

    while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
            USB_CLOCK_MASK) ;

    hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev));
    if (!hcd) {
        err("Failed to allocate HC buffer");
        ret = -ENOMEM;
        goto out3;
    }

    /* Set all USB bits in the Start Enable register */
    pnx4008_set_usb_bits();

    hcd->rsrc_start = pdev->resource[0].start;
    hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
    if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
        dev_dbg(&pdev->dev, "request_mem_region failed\n");
        ret =  -ENOMEM;
        goto out4;
    }
    hcd->regs = (void __iomem *)pdev->resource[0].start;

    irq = platform_get_irq(pdev, 0);
    if (irq < 0) {
        ret = -ENXIO;
        goto out4;
    }

    pnx4008_start_hc();
    platform_set_drvdata(pdev, hcd);
    ohci = hcd_to_ohci(hcd);
    ohci_hcd_init(ohci);

    dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
    ret = usb_add_hcd(hcd, irq, 0);
    if (ret == 0)
        return ret;

    pnx4008_stop_hc();
out4:
    pnx4008_unset_usb_bits();
    usb_put_hcd(hcd);
out3:
    clk_disable(usb_clk);
out2:
    clk_put(usb_clk);
out1:
    i2c_unregister_device(isp1301_i2c_client);
    isp1301_i2c_client = NULL;
out_i2c_driver:
    i2c_del_driver(&isp1301_driver);
out:
    return ret;
}