起初使用如下方式
&i2c1 {
alsps@44 {
ldo_hrs_pin = <&pio 177 0>;
....
};
};
在驱动中按如下的写法
LDO_HRS_PIN = of_get_named_gpio(client->dev.of_node,"ldo_hrs_pin", 0);
gpio_request(LDO_HRS_PIN, "LDO_HRS_PIN");
上述写法在32位kernel上没有问题,但是在64位kernel上会报 invalid GPIO 23062,从而导致ic上电失败,具体原因不详,希望大牛们指点一二,为了不耽误项目进度,因此选择用下面的方式进行控制。
dts中的写法
&i2c1 {
alsps@44 {
/* customization */
pinctrl-names = "hrs_en_low", "hrs_en_high";
pinctrl-0 = <&hrs_en_low>;
pinctrl-1 = <&hrs_en_high>;
status = "okay";
....
};
};
/* hrs3300 power control BEGIN*/
&pio {
hrs_en_low:hrs_en_low@gpio177{
pins_cmd_dat {
pinmux =
slew-rate = <1>;
output-low;
};
};
hrs_en_high:hrs_en_high@gpio177{
pins_cmd_dat {
pinmux =
slew-rate = <1>;
output-high;
};
};
};
/* hrs3300 power control end*/
驱动中的写法:
probe中添加pin control的初始化函数
static int hrs3300_i2c_probe(struct i2c_client *client, ...) {
...
power_pinctrl_init(client);
...
}
static int power_pinctrl_init(struct i2c_client *client)
{
int ret = 0;
/* get pinctrl */
power_pinctrl = devm_pinctrl_get(&client->dev);
if (IS_ERR(power_pinctrl)) {
printk("Failed to get hrs3300 pinctrl.\n");
ret = PTR_ERR(power_pinctrl);
return ret;
}
/* TODO: hrs3300 power XXX pin initialization */
power_xxx_high = pinctrl_lookup_state(
power_pinctrl, POWER_PINCTRL_STATE_XXX_HIGH);
if (IS_ERR(power_xxx_high)) {
printk("Failed to init (%s)\n", POWER_PINCTRL_STATE_XXX_HIGH);
ret = PTR_ERR(power_xxx_high);
}
power_xxx_low = pinctrl_lookup_state(
power_pinctrl, POWER_PINCTRL_STATE_XXX_LOW);
if (IS_ERR(power_xxx_low)) {
printk("Failed to init (%s)\n", POWER_PINCTRL_STATE_XXX_LOW);
ret = PTR_ERR(power_xxx_low);
}
return ret;
}
gpio控制的函数
static void hrs3300_power(struct hrate_hw *hw, unsigned int on)
{
static unsigned int power_on = 0;
if (power_xxx_low==NULL || power_xxx_high==NULL) {
pr_err("%s pin not init\n");
return;
}
if (!on && !IS_ERR(power_xxx_low))
pinctrl_select_state(power_pinctrl, power_xxx_low);
else if (on && !IS_ERR(power_xxx_high))
pinctrl_select_state(power_pinctrl, power_xxx_high);
else
pr_err("set err, pin\n");
}
变量声明如下
#define POWER_PINCTRL_STATE_XXX_HIGH "hrs_en_high"
#define POWER_PINCTRL_STATE_XXX_LOW "hrs_en_low"
static struct pinctrl *power_pinctrl=NULL;
static struct pinctrl_state *power_xxx_high=NULL;
static struct pinctrl_state *power_xxx_low=NULL;
在此做个笔记