예제 #1
0
파일: cpu.c 프로젝트: skelton/RK3288-tablet
static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	const char *type;

	if (cpu_is_rk3288())
		type = "rk3288";
	else if (cpu_is_rk319x())
		type = "rk319x";
	else if (cpu_is_rk3188())
		type = "rk3188";
	else if (cpu_is_rk3066b())
		type = "rk3066b";
	else if (cpu_is_rk3026())
		type = "rk3026";
	else if (cpu_is_rk30xx())
		type = "rk30xx";
	else if (cpu_is_rk2928())
		type = "rk2928";
	else if (cpu_is_rk312x())
		type = "rk312x";
	else
		type = "";

	if (rockchip_get_cpu_version())
		return sprintf(buf, "%sv%lu\n", type,
			       rockchip_get_cpu_version());

	return sprintf(buf, "%s\n", type);
}
static int wlan_platdata_parse_dt(struct device *dev,
                  struct rksdmmc_gpio_wifi_moudle *data)
{
    struct device_node *node = dev->of_node;
    const char *strings;
    u32 value;
    int gpio,ret;
    enum of_gpio_flags flags;

    if (!node)
        return -ENODEV;

    memset(data, 0, sizeof(*data));

    ret = of_property_read_string(node, "wifi_chip_type", &strings);
    if (ret) {
        LOG("%s: Can not read wifi_chip_type, set default to rkwifi.\n", __func__);
        strcpy(wifi_chip_type_string, "rkwifi");
    }
    strcpy(wifi_chip_type_string, strings);
    LOG("%s: wifi_chip_type = %s\n", __func__, wifi_chip_type_string);

	if(cpu_is_rk3036() || cpu_is_rk312x()){
		/* ret = of_property_read_u32(node, "sdio_vref", &value);
		if (ret < 0) {
			LOG("%s: Can't get sdio vref.", __func__);
			return -1;
		}
		data->sdio_vol = value;*/
	}else{
		ret = of_property_read_u32(node, "sdio_vref", &value);
		if (ret < 0) {
			LOG("%s: Can't get sdio vref.", __func__);
			return -1;
		}
		data->sdio_vol = value;
	}

    if (of_find_property(node, "keep_wifi_power_on", NULL)) {
        data->wifi_power_remain = true;
        LOG("%s: wifi power will enabled while kernel starting and keep on.\n", __func__);
    } else {
        data->wifi_power_remain = false;
        LOG("%s: enable wifi power control.\n", __func__);
    }
       
    if (of_find_property(node, "vref_ctrl_enable", NULL)) {
        LOG("%s: enable wifi io reference voltage control.\n", __func__);
        data->vref_ctrl_enble = true;
        if (of_find_property(node, "vref_ctrl_gpio", NULL)) {
            gpio = of_get_named_gpio_flags(node, "vref_ctrl_gpio", 0, &flags);
            if (gpio_is_valid(gpio)){
                data->vddio.io = gpio;
                data->vddio.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
                data->ioregulator.power_ctrl_by_pmu = false;
                LOG("%s: get property: vref_ctrl_gpio = %d, flags = %d.\n", __func__, gpio, flags);
            } else {
                data->vddio.io = -1;
                data->vref_ctrl_enble = false;
                LOG("%s: vref_ctrl_gpio defined invalid, disable wifi io reference voltage control.\n", __func__);
            }
        } else {
            data->ioregulator.power_ctrl_by_pmu = true;
            ret = of_property_read_string(node, "vref_pmu_regulator", &strings);
            if (ret) {
                LOG("%s: Can not read property: vref_pmu_regulator.\n", __func__);
                data->vref_ctrl_enble = false;
                data->ioregulator.power_ctrl_by_pmu = false;
            } else {
                LOG("%s: wifi io reference voltage controled by pmu(%s).\n", __func__, strings);
                sprintf(data->ioregulator.pmu_regulator, "%s", strings);
            }
            ret = of_property_read_u32(node, "vref_pmu_enable_level", &value);
            if (ret) {
                LOG("%s: Can not read property: vref_pmu_enable_level.\n", __func__);
                data->vref_ctrl_enble = false;
                data->ioregulator.power_ctrl_by_pmu = false;
            } else {
                LOG("%s: wifi io reference voltage controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
                data->ioregulator.enable = value;
            }
        }
    } else {
        data->vref_ctrl_enble = false;
        LOG("%s: disable wifi io reference voltage control.\n", __func__);
    }

    if (of_find_property(node, "power_ctrl_by_pmu", NULL)) {
        data->mregulator.power_ctrl_by_pmu = true;
        ret = of_property_read_string(node, "power_pmu_regulator", &strings);
        if (ret) {
            LOG("%s: Can not read property: power_pmu_regulator.\n", __func__);
            data->mregulator.power_ctrl_by_pmu = false;
        } else {
            LOG("%s: wifi power controled by pmu(%s).\n", __func__, strings);
            sprintf(data->mregulator.pmu_regulator, "%s", strings);
        }
        ret = of_property_read_u32(node, "power_pmu_enable_level", &value);
        if (ret) {
            LOG("%s: Can not read property: power_pmu_enable_level.\n", __func__);
            data->mregulator.power_ctrl_by_pmu = false;
        } else {
            LOG("%s: wifi power controled by pmu(level = %s).\n", __func__, (value == 1)?"HIGH":"LOW");
            data->mregulator.enable = value;
        }
	} else {
		data->mregulator.power_ctrl_by_pmu = false;
		LOG("%s: wifi power controled by gpio.\n", __func__);
        gpio = of_get_named_gpio_flags(node, "WIFI,poweren_gpio", 0, &flags);
        if (gpio_is_valid(gpio)){
			data->power_n.io = gpio;
			data->power_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
			LOG("%s: get property: WIFI,poweren_gpio = %d, flags = %d.\n", __func__, gpio, flags);
        } else data->power_n.io = -1;
        gpio = of_get_named_gpio_flags(node, "WIFI,reset_gpio", 0, &flags);
        if (gpio_is_valid(gpio)){
			data->reset_n.io = gpio;
			data->reset_n.enable = (flags == GPIO_ACTIVE_HIGH)? 1:0;
			LOG("%s: get property: WIFI,reset_gpio = %d, flags = %d.\n", __func__, gpio, flags);
        } else data->reset_n.io = -1;
        gpio = of_get_named_gpio_flags(node, "WIFI,host_wake_irq", 0, &flags);
        if (gpio_is_valid(gpio)){
			data->wifi_int_b.io = gpio;
			data->wifi_int_b.enable = flags;
			LOG("%s: get property: WIFI,host_wake_irq = %d, flags = %d.\n", __func__, gpio, flags);
        } else data->wifi_int_b.io = -1;
	}

    return 0;
}
/**************************************************************************
 *
 * wifi reference voltage control Func
 *
 *************************************************************************/
int rockchip_wifi_ref_voltage(int on)
{
    struct rfkill_wlan_data *mrfkill = g_rfkill;
    struct rksdmmc_gpio *vddio;
    struct regulator *ldo = NULL;
    int power = 0;
    bool toggle = false;

    LOG("%s: %d\n", __func__, on);

    if (mrfkill == NULL) {
        LOG("%s: rfkill-wlan driver has not Successful initialized\n", __func__);
        return -1;
    }

    if (!mrfkill->pdata->vref_ctrl_enble) {
        LOG("%s: wifi io reference voltage control is disabled.\n", __func__);
        return 0;
    }

    if (!rfkill_get_bt_power_state(&power, &toggle)) {
        if (power == 1) {
            LOG("%s: wifi shouldn't control io reference voltage, BT is running!\n", __func__);
            return 0;
        }
    }

    if (mrfkill->pdata->ioregulator.power_ctrl_by_pmu) {
        int ret = -1;
        char *ldostr;
        int level = mrfkill->pdata->ioregulator.enable;
		int voltage = 1000 * mrfkill->pdata->sdio_vol;

        ldostr = mrfkill->pdata->ioregulator.pmu_regulator;
        if (ldostr == NULL) {
            LOG("%s: wifi io reference voltage set to be controled by pmic, but which one?\n", __func__);
            return -1;
        }
        ldo = regulator_get(NULL, ldostr);
        if (ldo == NULL || IS_ERR(ldo)) {
            LOG("\n\n\n%s get ldo error,please mod this\n\n\n", __func__);
            return -1;
        } else {
            if (on == level) {
            	if(cpu_is_rk3036() || cpu_is_rk312x())
            	{
					/*regulator_set_voltage(ldo, voltage, voltage);
					LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
					ret = regulator_enable(ldo);
					LOG("wifi turn on io reference voltage.\n");*/
            	}else{
					regulator_set_voltage(ldo, voltage, voltage);
					LOG("%s: %s enabled, level = %d\n", __func__, ldostr, voltage);
					ret = regulator_enable(ldo);
					LOG("wifi turn on io reference voltage.\n");
            	}
            } else {
                LOG("%s: %s disabled\n", __func__, ldostr);
                while (regulator_is_enabled(ldo) > 0) {
                    ret = regulator_disable(ldo);
                }
                LOG("wifi shut off io reference voltage.\n");
            }
            regulator_put(ldo);
            msleep(100);
        }
    } else {
        vddio = &mrfkill->pdata->power_n;

        if (on){
            if (gpio_is_valid(vddio->io)) {
                gpio_set_value(vddio->io, vddio->enable);
                msleep(100);
            }

            LOG("wifi turn on io reference voltage.\n");
        }else{
            if (gpio_is_valid(vddio->io)) {
                gpio_set_value(vddio->io, !(vddio->enable));
                msleep(100);
            }

            LOG("wifi shut off io reference voltage.\n");
        }
    }

	return 0;
}