稳压器机器驱动接口

稳压器机器驱动接口旨在用于板级/机器特定的初始化代码,以配置稳压器子系统。

考虑以下机器

Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
             |
             +-> [Consumer B @ 3.3V]

为了控制电源,必须将消费者A和B的驱动程序映射到正确的稳压器。此映射可以在机器初始化代码中通过为每个稳压器创建struct regulator_consumer_supply来实现

struct regulator_consumer_supply {
      const char *dev_name;   /* consumer dev_name() */
      const char *supply;     /* consumer supply - e.g. "vcc" */
};

例如,对于上面的机器:

static struct regulator_consumer_supply regulator1_consumers[] = {
      REGULATOR_SUPPLY("Vcc", "consumer B"),
};

static struct regulator_consumer_supply regulator2_consumers[] = {
      REGULATOR_SUPPLY("Vcc", "consumer A"),
};

这将稳压器-1映射到消费者B的“Vcc”电源,并将稳压器-2映射到消费者A的“Vcc”电源。

现在可以通过为每个稳压器电源域定义struct regulator_init_data来注册约束。此结构还将消费者映射到其供电稳压器。

static struct regulator_init_data regulator1_data = {
      .constraints = {
              .name = "Regulator-1",
              .min_uV = 3300000,
              .max_uV = 3300000,
              .valid_modes_mask = REGULATOR_MODE_NORMAL,
      },
      .num_consumer_supplies = ARRAY_SIZE(regulator1_consumers),
      .consumer_supplies = regulator1_consumers,
};

name字段应设置为对板卡有用的描述性名称,以便配置其他稳压器的电源,并用于日志记录和其他诊断输出。通常,原理图中使用的电源轨名称是一个不错的选择。如果没有提供名称,则子系统将选择一个。

稳压器-1为稳压器-2供电。此关系必须在核心中注册,以便在消费者A启用其电源(稳压器-2)时也启用稳压器-1。供电稳压器由下面的supply_regulator字段设置,并且co

static struct regulator_init_data regulator2_data = {
      .supply_regulator = "Regulator-1",
      .constraints = {
              .min_uV = 1800000,
              .max_uV = 2000000,
              .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
              .valid_modes_mask = REGULATOR_MODE_NORMAL,
      },
      .num_consumer_supplies = ARRAY_SIZE(regulator2_consumers),
      .consumer_supplies = regulator2_consumers,
};

最后,必须以通常的方式注册稳压器设备。

static struct platform_device regulator_devices[] = {
      {
              .name = "regulator",
              .id = DCDC_1,
              .dev = {
                      .platform_data = &regulator1_data,
              },
      },
      {
              .name = "regulator",
              .id = DCDC_2,
              .dev = {
                      .platform_data = &regulator2_data,
              },
      },
};
/* register regulator 1 device */
platform_device_register(&regulator_devices[0]);

/* register regulator 2 device */
platform_device_register(&regulator_devices[1]);