mc13xxx.h 3.3 KB
Newer Older
Y
Yong Shen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
 *
 *  Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#ifndef __LINUX_REGULATOR_MC13XXX_H
#define __LINUX_REGULATOR_MC13XXX_H

#include <linux/regulator/driver.h>

struct mc13xxx_regulator {
	struct regulator_desc desc;
	int reg;
	int enable_bit;
	int vsel_reg;
	int vsel_shift;
	int vsel_mask;
	int hi_bit;
};

struct mc13xxx_regulator_priv {
	struct mc13xxx *mc13xxx;
	u32 powermisc_pwgt_state;
	struct mc13xxx_regulator *mc13xxx_regulators;
31
	int num_regulators;
Y
Yong Shen 已提交
32 33 34 35 36 37
	struct regulator_dev *regulators[];
};

extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
		int min_uV, int max_uV, unsigned *selector);

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#ifdef CONFIG_OF
extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
	int num_regulators);
#else
static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
{
	return -ENODEV;
}

static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
	int num_regulators)
{
	return NULL;
}
#endif

Y
Yong Shen 已提交
57 58 59 60 61 62
extern struct regulator_ops mc13xxx_regulator_ops;
extern struct regulator_ops mc13xxx_fixed_regulator_ops;

#define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops)	\
	[prefix ## _name] = {				\
		.desc = {						\
63
			.name = #_name,					\
Y
Yong Shen 已提交
64
			.n_voltages = ARRAY_SIZE(_voltages),		\
65
			.volt_table =  _voltages,			\
Y
Yong Shen 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
			.ops = &_ops,			\
			.type = REGULATOR_VOLTAGE,			\
			.id = prefix ## _name,		\
			.owner = THIS_MODULE,				\
		},							\
		.reg = prefix ## _reg,				\
		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
		.vsel_reg = prefix ## _vsel_reg,			\
		.vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
		.vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
	}

#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops)	\
	[prefix ## _name] = {				\
		.desc = {						\
81
			.name = #_name,					\
Y
Yong Shen 已提交
82
			.n_voltages = ARRAY_SIZE(_voltages),		\
83
			.volt_table =  _voltages,			\
Y
Yong Shen 已提交
84 85 86 87 88 89 90 91 92 93 94 95
			.ops = &_ops,		\
			.type = REGULATOR_VOLTAGE,			\
			.id = prefix ## _name,		\
			.owner = THIS_MODULE,				\
		},							\
		.reg = prefix ## _reg,				\
		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
	}

#define MC13xxx_GPO_DEFINE(prefix, _name, _reg,  _voltages, _ops)	\
	[prefix ## _name] = {				\
		.desc = {						\
96
			.name = #_name,					\
Y
Yong Shen 已提交
97
			.n_voltages = ARRAY_SIZE(_voltages),		\
98
			.volt_table =  _voltages,			\
Y
Yong Shen 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
			.ops = &_ops,		\
			.type = REGULATOR_VOLTAGE,			\
			.id = prefix ## _name,		\
			.owner = THIS_MODULE,				\
		},							\
		.reg = prefix ## _reg,				\
		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
	}

#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops)	\
	MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
#define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops)	\
	MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)

#endif