Пример #1
0
void iphone_pmu_charge_settings(int UseUSB, int SuspendUSB, int StopCharger)
{
	PowerSupplyType type = iphone_pmu_get_power_supply();

	if(type != PowerSupplyTypeUSBHost)	// No need to suspend USB, since we're not plugged into a USB host
		SuspendUSB = 0;

	if(SuspendUSB)
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_SUSPEND, 1);
	else
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_SUSPEND, 0);

	if(StopCharger) {
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_SUSPEND, 1);
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_SHUTDOWN, 1);
	} else {
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_SUSPEND, 0);
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_SHUTDOWN, 0);
	}

	if(type == PowerSupplyTypeUSBBrick500mA || type == PowerSupplyTypeUSBBrick1000mA || (type == PowerSupplyTypeUSBHost && UseUSB))
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_500_1000, 1);
	else
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_500_1000, 0);

	if(type == PowerSupplyTypeUSBBrick1000mA)
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_1000, 1);
	else
		iphone_gpio_pin_output(PMU_GPIO_CHARGER_USB_1000, 0);
}
Пример #2
0
static PowerSupplyType identify_usb_charger(void) {
	int dn;
	int dp;
	int x;

	iphone_gpio_pin_output(PMU_GPIO_CHARGER_IDENTIFY_DN, 1);
	dn = query_adc(PMU_ADCC1_ADCINMUX_ADCIN2_DIV << PMU_ADCC1_ADCINMUX_SHIFT);
	if(dn < 0)
		dn = 0;
	iphone_gpio_pin_output(PMU_GPIO_CHARGER_IDENTIFY_DN, 0);

	iphone_gpio_pin_output(PMU_GPIO_CHARGER_IDENTIFY_DP, 1);
	dp = query_adc(PMU_ADCC1_ADCINMUX_ADCIN2_DIV << PMU_ADCC1_ADCINMUX_SHIFT);
	if(dp < 0)
		dp = 0;
	iphone_gpio_pin_output(PMU_GPIO_CHARGER_IDENTIFY_DP, 0);

	if(dn < 99 || dp < 99) {
		return PowerSupplyTypeUSBHost;
	}

	x = (dn * 1000) / dp;
	if((x - 1291) <= 214) {
		return PowerSupplyTypeUSBBrick1000mA;
	}

	if((x - 901) <= 219 && dn <= 367 ) {
		return PowerSupplyTypeUSBBrick500mA;
	} else {
		return PowerSupplyTypeUSBHost;
	}
}
Пример #3
0
static int iphone_spi_mrdy_cs(struct spi_device *_dev, unsigned int _active)
{
	int mrdy = ((uint32_t)_dev->controller_data) >> 16;
	int srdy = ((uint32_t)_dev->controller_data) & 0xFFFF;

	dev_dbg(&_dev->dev, "setting MRDY GPIO to %d.\n", _active);

	switch(_active)
	{
		case 1: // Rx
			{
				int i = 0;
				while(iphone_gpio_pin_state(srdy) == 0)
				{
					msleep(1);

					i++;

					if(i >= 2000)
					{
						dev_err(&_dev->dev, "SPI device has no data.\n");
						return 0;
					}
				}
			}
			break;

		case 2: // Tx
			{
				int i = 0;
				iphone_gpio_pin_output(mrdy, 1);
				while(iphone_gpio_pin_state(srdy) == 0)
				{
					msleep(1);

					i++;

					if(i >= 2000)
					{
						dev_err(&_dev->dev, "SPI device never became ready.\n");
						iphone_gpio_pin_output(mrdy, 0);
						return -EIO;
					}
				}
			}
			break;

		default: // Disable
			{
				iphone_gpio_pin_output(mrdy, 0);
			}
			break;
	}

	return 0;
}
Пример #4
0
static int iphone_spi_gpio_cs(struct spi_device *_dev, unsigned int _active)
{
	if(_active > 0)
		_active = 1;

	if((_dev->mode & SPI_CS_HIGH) == 0)
		_active = 1-_active;

	dev_dbg(&_dev->dev, "chip-select setting GPIO 0x%04x to %d.\n", (uint32_t)_dev->controller_data, _active);

	iphone_gpio_pin_output((uint32_t)_dev->controller_data, _active);

	return 0;
}