static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) { struct twlreg_info *info = rdev_get_drvdata(rdev); unsigned message; int status; /* We can only set the mode through state machine commands... */ switch (mode) { case REGULATOR_MODE_NORMAL: message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); break; case REGULATOR_MODE_STANDBY: message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); break; default: return -EINVAL; } /* Ensure the resource is associated with some group */ status = twl4030reg_grp(rdev); if (status < 0) return status; if (!(status & (P3_GRP | P2_GRP | P1_GRP))) return -EACCES; status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, message >> 8, 0x15 /* PB_WORD_MSB */ ); if (status >= 0) return status; return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, message, 0x16 /* PB_WORD_LSB */ ); }
static int twl4030reg_is_enabled(struct regulator_dev *rdev) { int state = twl4030reg_grp(rdev); if (state < 0) return state; return (state & P1_GRP) != 0; }
static int twl4030reg_is_enabled(struct regulator_dev *rdev) { int state = twl4030reg_grp(rdev); if (state < 0) return state; /* resource state == OFF (vs SLEEP or ACTIVE) */ return (state & 0x0f) != 0; }
static int twl4030reg_get_status(struct regulator_dev *rdev) { int state = twl4030reg_grp(rdev); if (state < 0) return state; state &= 0x0f; /* assume state != WARM_RESET; we'd not be running... */ if (!state) return REGULATOR_STATUS_OFF; return (state & BIT(3)) ? REGULATOR_STATUS_NORMAL : REGULATOR_STATUS_STANDBY; }