⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tps65010.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
		omap_set_gpio_direction(OMAP_MPUIO(1), 1);		set_irq_type(tps->irq, IRQT_FALLING);	}	if (machine_is_omap_h3()) {		tps->model = TPS65013;		// FIXME set up this board's IRQ ...	}#else#define set_irq_type(num,trigger)	do{}while(0)#endif	if (tps->irq > 0) {		set_irq_type(tps->irq, IRQT_LOW);		status = request_irq(tps->irq, tps65010_irq,			SA_SAMPLE_RANDOM, DRIVER_NAME, tps);		if (status < 0) {			dev_dbg(&tps->client.dev, "can't get IRQ %d, err %d\n",					tps->irq, status);			i2c_detach_client(&tps->client);			goto fail1;		}#ifdef	CONFIG_ARM		/* annoying race here, ideally we'd have an option		 * to claim the irq now and enable it later.		 */		disable_irq(tps->irq);		set_bit(FLAG_IRQ_ENABLE, &tps->flags);#endif	} else		printk(KERN_WARNING "%s: IRQ not configured!\n",				DRIVER_NAME);	switch (tps->model) {	case TPS65010:	case TPS65012:		tps->por = 1;		break;	case TPS_UNKNOWN:		printk(KERN_WARNING "%s: unknown TPS chip\n", DRIVER_NAME);		break;	/* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */	}	tps->chgconf = i2c_smbus_read_byte_data(&tps->client, TPS_CHGCONFIG);	show_chgconfig(tps->por, "conf/init", tps->chgconf);	show_chgstatus("chg/init",		i2c_smbus_read_byte_data(&tps->client, TPS_CHGSTATUS));	show_regstatus("reg/init",		i2c_smbus_read_byte_data(&tps->client, TPS_REGSTATUS));	pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,		i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC1),		i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC2),		i2c_smbus_read_byte_data(&tps->client, TPS_VREGS1));	pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,		i2c_smbus_read_byte_data(&tps->client, TPS_DEFGPIO),		i2c_smbus_read_byte_data(&tps->client, TPS_MASK3));	tps65010_driver.attach_adapter = tps65010_noscan;	the_tps = tps;#if	defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)	/* USB hosts can't draw VBUS.  OTG devices could, later	 * when OTG infrastructure enables it.  USB peripherals	 * could be relying on VBUS while booting, though.	 */	tps->vbus = 100;#endif	/* unmask the "interesting" irqs, then poll once to	 * kickstart monitoring, initialize shadowed status	 * registers, and maybe disable VBUS draw.	 */	tps->nmask1 = ~0;	(void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK1, ~tps->nmask1);	tps->nmask2 = TPS_REG_ONOFF;	if (tps->model == TPS65013)		tps->nmask2 |= TPS_REG_NO_CHG;	(void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK2, ~tps->nmask2);	(void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK3, 0x0f		| i2c_smbus_read_byte_data(&tps->client, TPS_MASK3));	tps65010_work(tps);	tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,				tps, DEBUG_FOPS);	return 0;fail1:	kfree(tps);	return 0;}static int __init tps65010_scan_bus(struct i2c_adapter *bus){	if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA))		return -EINVAL;	return i2c_probe(bus, &addr_data, tps65010_probe);}static struct i2c_driver tps65010_driver = {	.owner		= THIS_MODULE,	.name		= "tps65010",	.flags		= I2C_DF_NOTIFY,	.attach_adapter	= tps65010_scan_bus,	.detach_client	= __exit_p(tps65010_detach_client),};/*-------------------------------------------------------------------------*//* Draw from VBUS: *   0 mA -- DON'T DRAW (might supply power instead) * 100 mA -- usb unit load (slowest charge rate) * 500 mA -- usb high power (fast battery charge) */int tps65010_set_vbus_draw(unsigned mA){	unsigned long	flags;	if (!the_tps)		return -ENODEV;	/* assumes non-SMP */	local_irq_save(flags);	if (mA >= 500)		mA = 500;	else if (mA >= 100)		mA = 100;	else		mA = 0;	the_tps->vbus = mA;	if ((the_tps->chgstatus & TPS_CHG_USB)			&& test_and_set_bit(				FLAG_VBUS_CHANGED, &the_tps->flags)) {		/* gadget drivers call this in_irq() */		(void) schedule_work(&the_tps->work);	}	local_irq_restore(flags);	return 0;}EXPORT_SYMBOL(tps65010_set_vbus_draw);/*-------------------------------------------------------------------------*//* tps65010_set_gpio_out_value parameter: * gpio:  GPIO1, GPIO2, GPIO3 or GPIO4 * value: LOW or HIGH */int tps65010_set_gpio_out_value(unsigned gpio, unsigned value){	int	 status;	unsigned defgpio;	if (!the_tps)		return -ENODEV;	if ((gpio < GPIO1) || (gpio > GPIO4))		return -EINVAL;	down(&the_tps->lock);	defgpio = i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO);	/* Configure GPIO for output */	defgpio |= 1 << (gpio + 3);	/* Writing 1 forces a logic 0 on that GPIO and vice versa */	switch (value) {	case LOW:		defgpio |= 1 << (gpio - 1);    /* set GPIO low by writing 1 */		break;	/* case HIGH: */	default:		defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */		break;	}	status = i2c_smbus_write_byte_data(&the_tps->client,		TPS_DEFGPIO, defgpio);	pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,		gpio, value ? "high" : "low",		i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO));	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65010_set_gpio_out_value);/*-------------------------------------------------------------------------*//* tps65010_set_led parameter: * led:  LED1 or LED2 * mode: ON, OFF or BLINK */int tps65010_set_led(unsigned led, unsigned mode){	int	 status;	unsigned led_on, led_per, offs;	if (!the_tps)		return -ENODEV;	if (led == LED1)		offs = 0;	else {		offs = 2;		led = LED2;	}	down(&the_tps->lock);	pr_debug("%s: led%i_on   0x%02x\n", DRIVER_NAME, led,		i2c_smbus_read_byte_data(&the_tps->client,				TPS_LED1_ON + offs));	pr_debug("%s: led%i_per  0x%02x\n", DRIVER_NAME, led,		i2c_smbus_read_byte_data(&the_tps->client,				TPS_LED1_PER + offs));	switch (mode) {	case OFF:		led_on  = 1 << 7;		led_per = 0 << 7;		break;	case ON:		led_on  = 1 << 7;		led_per = 1 << 7;		break;	case BLINK:		led_on  = 0x30 | (0 << 7);		led_per = 0x08 | (1 << 7);		break;	default:		printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",		       DRIVER_NAME);		up(&the_tps->lock);		return -EINVAL;	}	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_LED1_ON + offs, led_on);	if (status != 0) {		printk(KERN_ERR "%s: Failed to write led%i_on register\n",		       DRIVER_NAME, led);		up(&the_tps->lock);		return status;	}	pr_debug("%s: led%i_on   0x%02x\n", DRIVER_NAME, led,		i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs));	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_LED1_PER + offs, led_per);	if (status != 0) {		printk(KERN_ERR "%s: Failed to write led%i_per register\n",		       DRIVER_NAME, led);		up(&the_tps->lock);		return status;	}	pr_debug("%s: led%i_per  0x%02x\n", DRIVER_NAME, led,		i2c_smbus_read_byte_data(&the_tps->client,				TPS_LED1_PER + offs));	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65010_set_led);/*-------------------------------------------------------------------------*//* tps65010_set_vib parameter: * value: ON or OFF */int tps65010_set_vib(unsigned value){	int	 status;	unsigned vdcdc2;	if (!the_tps)		return -ENODEV;	down(&the_tps->lock);	vdcdc2 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC2);	vdcdc2 &= ~(1 << 1);	if (value)		vdcdc2 |= (1 << 1);	status = i2c_smbus_write_byte_data(&the_tps->client,		TPS_VDCDC2, vdcdc2);	pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65010_set_vib);/*-------------------------------------------------------------------------*//* tps65010_set_low_pwr parameter: * mode: ON or OFF */int tps65010_set_low_pwr(unsigned mode){	int	 status;	unsigned vdcdc1;	if (!the_tps)		return -ENODEV;	down(&the_tps->lock);	pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,		mode ? "enable" : "disable",		i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));	vdcdc1 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1);	switch (mode) {	case OFF:		vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */		break;	/* case ON: */	default:		vdcdc1 |= TPS_ENABLE_LP;  /* enable ENABLE_LP bit */		break;	}	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_VDCDC1, vdcdc1);	if (status != 0)		printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",			DRIVER_NAME);	else		pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,			i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65010_set_low_pwr);/*-------------------------------------------------------------------------*//* tps65010_config_vregs1 parameter: * value to be written to VREGS1 register * Note: The complete register is written, set all bits you need */int tps65010_config_vregs1(unsigned value){	int	 status;	if (!the_tps)		return -ENODEV;	down(&the_tps->lock);	pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,			i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_VREGS1, value);	if (status != 0)		printk(KERN_ERR "%s: Failed to write vregs1 register\n",			DRIVER_NAME);	else		pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,			i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65010_config_vregs1);/*-------------------------------------------------------------------------*//* tps65013_set_low_pwr parameter: * mode: ON or OFF *//* FIXME: Assumes AC or USB power is present. Setting AUA bit is not	required if power supply is through a battery */int tps65013_set_low_pwr(unsigned mode){	int	 status;	unsigned vdcdc1, chgconfig;	if (!the_tps || the_tps->por)		return -ENODEV;	down(&the_tps->lock);	pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",		DRIVER_NAME,		mode ? "enable" : "disable",		i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG),		i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));	chgconfig = i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG);	vdcdc1 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1);	switch (mode) {	case OFF:		chgconfig &= ~TPS65013_AUA; /* disable AUA bit */		vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */		break;	/* case ON: */	default:		chgconfig |= TPS65013_AUA;  /* enable AUA bit */		vdcdc1 |= TPS_ENABLE_LP;  /* enable ENABLE_LP bit */		break;	}	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_CHGCONFIG, chgconfig);	if (status != 0) {		printk(KERN_ERR "%s: Failed to write chconfig register\n",	 DRIVER_NAME);		up(&the_tps->lock);		return status;	}	chgconfig = i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG);	the_tps->chgconf = chgconfig;	show_chgconfig(0, "chgconf", chgconfig);	status = i2c_smbus_write_byte_data(&the_tps->client,			TPS_VDCDC1, vdcdc1);	if (status != 0)		printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",	 DRIVER_NAME);	else		pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,			i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));	up(&the_tps->lock);	return status;}EXPORT_SYMBOL(tps65013_set_low_pwr);/*-------------------------------------------------------------------------*/static int __init tps_init(void){	u32	tries = 3;	int	status = -ENODEV;	printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION);	/* some boards have startup glitches */	while (tries--) {		status = i2c_add_driver(&tps65010_driver);		if (the_tps)			break;		i2c_del_driver(&tps65010_driver);		if (!tries) {			printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME);			return -ENODEV;		}		pr_debug("%s: re-probe ...\n", DRIVER_NAME);		msleep(10);	}#ifdef	CONFIG_ARM	if (machine_is_omap_osk()) {		// FIXME: More should be placed in the initialization code		//	  of the submodules (DSP, ethernet, power management,		//	  board-osk.c). Careful: I2C is initialized "late".		/* Let LED1 (D9) blink */		tps65010_set_led(LED1, BLINK);		/* Disable LED 2 (D2) */		tps65010_set_led(LED2, OFF);		/* Set GPIO 1 HIGH to disable VBUS power supply;		 * OHCI driver powers it up/down as needed.		 */		tps65010_set_gpio_out_value(GPIO1, HIGH);		/* Set GPIO 2 low to turn on LED D3 */		tps65010_set_gpio_out_value(GPIO2, HIGH);		/* Set GPIO 3 low to take ethernet out of reset */		tps65010_set_gpio_out_value(GPIO3, LOW);		/* gpio4 for VDD_DSP */		/* Enable LOW_PWR */		tps65010_set_low_pwr(ON);		/* Switch VLDO2 to 3.0V for AIC23 */		tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V | TPS_LDO1_ENABLE);	} else if (machine_is_omap_h2()) {		/* gpio3 for SD, gpio4 for VDD_DSP */		/* Enable LOW_PWR */		tps65010_set_low_pwr(ON);	} else if (machine_is_omap_h3()) {		/* gpio4 for SD, gpio3 for VDD_DSP */#ifdef CONFIG_PM		/* Enable LOW_PWR */		tps65013_set_low_pwr(ON);#endif	}#endif	return status;}/* NOTE:  this MUST be initialized before the other parts of the system * that rely on it ... but after the i2c bus on which this relies. * That is, much earlier than on PC-type systems, which don't often use * I2C as a core system bus. */subsys_initcall(tps_init);static void __exit tps_exit(void){	i2c_del_driver(&tps65010_driver);}module_exit(tps_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -