Skip to content
Snippets Groups Projects
Select Git revision
  • 733ada000f2c9618ccbac7b9ba146113f0a6675b
  • openEuler-1.0-LTS default protected
  • openEuler-22.09
  • OLK-5.10
  • openEuler-22.03-LTS
  • openEuler-22.03-LTS-Ascend
  • master
  • openEuler-22.03-LTS-LoongArch-NW
  • openEuler-22.09-HCK
  • openEuler-20.03-LTS-SP3
  • openEuler-21.09
  • openEuler-21.03
  • openEuler-20.09
  • 4.19.90-2210.5.0
  • 5.10.0-123.0.0
  • 5.10.0-60.63.0
  • 5.10.0-60.62.0
  • 4.19.90-2210.4.0
  • 5.10.0-121.0.0
  • 5.10.0-60.61.0
  • 4.19.90-2210.3.0
  • 5.10.0-60.60.0
  • 5.10.0-120.0.0
  • 5.10.0-60.59.0
  • 5.10.0-119.0.0
  • 4.19.90-2210.2.0
  • 4.19.90-2210.1.0
  • 5.10.0-118.0.0
  • 5.10.0-106.19.0
  • 5.10.0-60.58.0
  • 4.19.90-2209.6.0
  • 5.10.0-106.18.0
  • 5.10.0-106.17.0
33 results

pwm-regulator.c

Blame
  • pwm-regulator.c 4.67 KiB
    /*
     * Regulator driver for PWM Regulators
     *
     * Copyright (C) 2014 - STMicroelectronics Inc.
     *
     * Author: Lee Jones <lee.jones@linaro.org>
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     */
    
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/err.h>
    #include <linux/regulator/driver.h>
    #include <linux/regulator/machine.h>
    #include <linux/regulator/of_regulator.h>
    #include <linux/of.h>
    #include <linux/of_device.h>
    #include <linux/pwm.h>
    
    struct pwm_regulator_data {
    	struct pwm_voltages *duty_cycle_table;
    	struct pwm_device *pwm;
    	int state;
    };
    
    struct pwm_voltages {
    	unsigned int uV;
    	unsigned int dutycycle;
    };
    
    static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev)
    {
    	struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
    
    	return drvdata->state;
    }
    
    static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
    					 unsigned selector)
    {
    	struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
    	unsigned int pwm_reg_period;
    	int dutycycle;
    	int ret;
    
    	pwm_reg_period = pwm_get_period(drvdata->pwm);
    
    	dutycycle = (pwm_reg_period *
    		    drvdata->duty_cycle_table[selector].dutycycle) / 100;
    
    	ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period);
    	if (ret) {
    		dev_err(&rdev->dev, "Failed to configure PWM\n");
    		return ret;
    	}
    
    	drvdata->state = selector;
    
    	ret = pwm_enable(drvdata->pwm);
    	if (ret) {
    		dev_err(&rdev->dev, "Failed to enable PWM\n");
    		return ret;
    	}
    
    	return 0;
    }