1296906Smmel/*- 2296906Smmel * Copyright 2016 Michal Meloun <mmel@FreeBSD.org> 3296906Smmel * All rights reserved. 4296906Smmel * 5296906Smmel * Redistribution and use in source and binary forms, with or without 6296906Smmel * modification, are permitted provided that the following conditions 7296906Smmel * are met: 8296906Smmel * 1. Redistributions of source code must retain the above copyright 9296906Smmel * notice, this list of conditions and the following disclaimer. 10296906Smmel * 2. Redistributions in binary form must reproduce the above copyright 11296906Smmel * notice, this list of conditions and the following disclaimer in the 12296906Smmel * documentation and/or other materials provided with the distribution. 13296906Smmel * 14296906Smmel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15296906Smmel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16296906Smmel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17296906Smmel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18296906Smmel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19296906Smmel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20296906Smmel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21296906Smmel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22296906Smmel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23296906Smmel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24296906Smmel * SUCH DAMAGE. 25296906Smmel * 26296906Smmel * $FreeBSD: releng/11.0/sys/dev/extres/regulator/regulator.h 296906 2016-03-15 15:30:17Z mmel $ 27296906Smmel */ 28296906Smmel 29296906Smmel#ifndef _DEV_EXTRES_REGULATOR_H_ 30296906Smmel#define _DEV_EXTRES_REGULATOR_H_ 31296906Smmel#include "opt_platform.h" 32296906Smmel 33296906Smmel#include <sys/kobj.h> 34296906Smmel#ifdef FDT 35296906Smmel#include <dev/ofw/ofw_bus.h> 36296906Smmel#endif 37296906Smmel#include "regnode_if.h" 38296906Smmel 39296906Smmel#define REGULATOR_FLAGS_STATIC 0x00000001 /* Static strings */ 40296906Smmel#define REGULATOR_FLAGS_NOT_DISABLE 0x00000002 /* Cannot be disabled */ 41296906Smmel 42296906Smmel#define REGULATOR_STATUS_ENABLED 0x00000001 43296906Smmel#define REGULATOR_STATUS_OVERCURRENT 0x00000002 44296906Smmel 45296906Smmeltypedef struct regulator *regulator_t; 46296906Smmel 47296906Smmel/* Standard regulator parameters. */ 48296906Smmelstruct regnode_std_param { 49296906Smmel int min_uvolt; /* In uV */ 50296906Smmel int max_uvolt; /* In uV */ 51296906Smmel int min_uamp; /* In uA */ 52296906Smmel int max_uamp; /* In uA */ 53296906Smmel int ramp_delay; /* In uV/usec */ 54296906Smmel int enable_delay; /* In usec */ 55296906Smmel bool boot_on; /* Is enabled on boot */ 56296906Smmel bool always_on; /* Must be enabled */ 57296906Smmel int enable_active_high; 58296906Smmel}; 59296906Smmel 60296906Smmel/* Initialization parameters. */ 61296906Smmelstruct regnode_init_def { 62296906Smmel char *name; /* Regulator name */ 63296906Smmel char *parent_name; /* Name of parent regulator */ 64296906Smmel struct regnode_std_param std_param; /* Standard parameters */ 65296906Smmel intptr_t id; /* Regulator ID */ 66296906Smmel int flags; /* Flags */ 67296906Smmel#ifdef FDT 68296906Smmel phandle_t ofw_node; /* OFW node of regulator */ 69296906Smmel#endif 70296906Smmel 71296906Smmel}; 72296906Smmel 73296906Smmel/* 74296906Smmel * Shorthands for constructing method tables. 75296906Smmel */ 76296906Smmel#define REGNODEMETHOD KOBJMETHOD 77296906Smmel#define REGNODEMETHOD_END KOBJMETHOD_END 78296906Smmel#define regnode_method_t kobj_method_t 79296906Smmel#define regnode_class_t kobj_class_t 80296906SmmelDECLARE_CLASS(regnode_class); 81296906Smmel 82296906Smmel/* Providers interface. */ 83296906Smmelstruct regnode *regnode_create(device_t pdev, regnode_class_t regnode_class, 84296906Smmel struct regnode_init_def *def); 85296906Smmelstruct regnode *regnode_register(struct regnode *regnode); 86296906Smmelconst char *regnode_get_name(struct regnode *regnode); 87296906Smmelconst char *regnode_get_parent_name(struct regnode *regnode); 88296906Smmelstruct regnode *regnode_get_parent(struct regnode *regnode); 89296906Smmelint regnode_get_flags(struct regnode *regnode); 90296906Smmelvoid *regnode_get_softc(struct regnode *regnode); 91296906Smmeldevice_t regnode_get_device(struct regnode *regnode); 92296906Smmelstruct regnode_std_param *regnode_get_stdparam(struct regnode *regnode); 93296906Smmelvoid regnode_topo_unlock(void); 94296906Smmelvoid regnode_topo_xlock(void); 95296906Smmelvoid regnode_topo_slock(void); 96296906Smmel 97296906Smmelint regnode_enable(struct regnode *regnode); 98296906Smmelint regnode_disable(struct regnode *regnode); 99296906Smmelint regnode_stop(struct regnode *regnode, int depth); 100296906Smmelint regnode_status(struct regnode *regnode, int *status); 101296906Smmelint regnode_get_voltage(struct regnode *regnode, int *uvolt); 102296906Smmelint regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt); 103296906Smmel#ifdef FDT 104296906Smmelphandle_t regnode_get_ofw_node(struct regnode *regnode); 105296906Smmel#endif 106296906Smmel 107296906Smmel/* Consumers interface. */ 108296906Smmelint regulator_get_by_name(device_t cdev, const char *name, 109296906Smmel regulator_t *regulator); 110296906Smmelint regulator_get_by_id(device_t cdev, device_t pdev, intptr_t id, 111296906Smmel regulator_t *regulator); 112296906Smmelint regulator_release(regulator_t regulator); 113296906Smmelconst char *regulator_get_name(regulator_t regulator); 114296906Smmelint regulator_enable(regulator_t reg); 115296906Smmelint regulator_disable(regulator_t reg); 116296906Smmelint regulator_stop(regulator_t reg); 117296906Smmelint regulator_status(regulator_t reg, int *status); 118296906Smmelint regulator_get_voltage(regulator_t reg, int *uvolt); 119296906Smmelint regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt); 120296906Smmel 121296906Smmel#ifdef FDT 122296906Smmelint regulator_get_by_ofw_property(device_t dev, char *name, regulator_t *reg); 123296906Smmelint regulator_parse_ofw_stdparam(device_t dev, phandle_t node, 124296906Smmel struct regnode_init_def *def); 125296906Smmel#endif 126296906Smmel 127296906Smmel#endif /* _DEV_EXTRES_REGULATOR_H_ */ 128