1*e1ae0d1fSSimon Glass /* 2*e1ae0d1fSSimon Glass * Tegra pulse width frequency modulator definitions 3*e1ae0d1fSSimon Glass * 4*e1ae0d1fSSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 5*e1ae0d1fSSimon Glass * See file CREDITS for list of people who contributed to this 6*e1ae0d1fSSimon Glass * project. 7*e1ae0d1fSSimon Glass * 8*e1ae0d1fSSimon Glass * This program is free software; you can redistribute it and/or 9*e1ae0d1fSSimon Glass * modify it under the terms of the GNU General Public License as 10*e1ae0d1fSSimon Glass * published by the Free Software Foundation; either version 2 of 11*e1ae0d1fSSimon Glass * the License, or (at your option) any later version. 12*e1ae0d1fSSimon Glass * 13*e1ae0d1fSSimon Glass * This program is distributed in the hope that it will be useful, 14*e1ae0d1fSSimon Glass * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*e1ae0d1fSSimon Glass * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*e1ae0d1fSSimon Glass * GNU General Public License for more details. 17*e1ae0d1fSSimon Glass * 18*e1ae0d1fSSimon Glass * You should have received a copy of the GNU General Public License 19*e1ae0d1fSSimon Glass * along with this program; if not, write to the Free Software 20*e1ae0d1fSSimon Glass * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*e1ae0d1fSSimon Glass * MA 02111-1307 USA 22*e1ae0d1fSSimon Glass */ 23*e1ae0d1fSSimon Glass 24*e1ae0d1fSSimon Glass #ifndef __ASM_ARCH_TEGRA_PWM_H 25*e1ae0d1fSSimon Glass #define __ASM_ARCH_TEGRA_PWM_H 26*e1ae0d1fSSimon Glass 27*e1ae0d1fSSimon Glass /* This is a single PWM channel */ 28*e1ae0d1fSSimon Glass struct pwm_ctlr { 29*e1ae0d1fSSimon Glass uint control; /* Control register */ 30*e1ae0d1fSSimon Glass uint reserved[3]; /* Space space */ 31*e1ae0d1fSSimon Glass }; 32*e1ae0d1fSSimon Glass 33*e1ae0d1fSSimon Glass #define PWM_NUM_CHANNELS 4 34*e1ae0d1fSSimon Glass 35*e1ae0d1fSSimon Glass /* PWM_CONTROLLER_PWM_CSR_0/1/2/3_0 */ 36*e1ae0d1fSSimon Glass #define PWM_ENABLE_SHIFT 31 37*e1ae0d1fSSimon Glass #define PWM_ENABLE_MASK (0x1 << PWM_ENABLE_SHIFT) 38*e1ae0d1fSSimon Glass 39*e1ae0d1fSSimon Glass #define PWM_WIDTH_SHIFT 16 40*e1ae0d1fSSimon Glass #define PWM_WIDTH_MASK (0x7FFF << PWM_WIDTH_SHIFT) 41*e1ae0d1fSSimon Glass 42*e1ae0d1fSSimon Glass #define PWM_DIVIDER_SHIFT 0 43*e1ae0d1fSSimon Glass #define PWM_DIVIDER_MASK (0x1FFF << PWM_DIVIDER_SHIFT) 44*e1ae0d1fSSimon Glass 45*e1ae0d1fSSimon Glass /** 46*e1ae0d1fSSimon Glass * Program the PWM with the given parameters. 47*e1ae0d1fSSimon Glass * 48*e1ae0d1fSSimon Glass * @param channel PWM channel to update 49*e1ae0d1fSSimon Glass * @param rate Clock rate to use for PWM 50*e1ae0d1fSSimon Glass * @param pulse_width high pulse width: 0=always low, 1=1/256 pulse high, 51*e1ae0d1fSSimon Glass * n = n/256 pulse high 52*e1ae0d1fSSimon Glass * @param freq_divider frequency divider value (1 to use rate as is) 53*e1ae0d1fSSimon Glass */ 54*e1ae0d1fSSimon Glass void pwm_enable(unsigned channel, int rate, int pulse_width, int freq_divider); 55*e1ae0d1fSSimon Glass 56*e1ae0d1fSSimon Glass /** 57*e1ae0d1fSSimon Glass * Request a pwm channel as referenced by a device tree node. 58*e1ae0d1fSSimon Glass * 59*e1ae0d1fSSimon Glass * This channel can then be passed to pwm_enable(). 60*e1ae0d1fSSimon Glass * 61*e1ae0d1fSSimon Glass * @param blob Device tree blob 62*e1ae0d1fSSimon Glass * @param node Node containing reference to pwm 63*e1ae0d1fSSimon Glass * @param prop_name Property name of pwm reference 64*e1ae0d1fSSimon Glass * @return channel number, if ok, else -1 65*e1ae0d1fSSimon Glass */ 66*e1ae0d1fSSimon Glass int pwm_request(const void *blob, int node, const char *prop_name); 67*e1ae0d1fSSimon Glass 68*e1ae0d1fSSimon Glass /** 69*e1ae0d1fSSimon Glass * Set up the pwm controller, by looking it up in the fdt. 70*e1ae0d1fSSimon Glass * 71*e1ae0d1fSSimon Glass * @return 0 if ok, -1 if the device tree node was not found or invalid. 72*e1ae0d1fSSimon Glass */ 73*e1ae0d1fSSimon Glass int pwm_init(const void *blob); 74*e1ae0d1fSSimon Glass 75*e1ae0d1fSSimon Glass #endif /* __ASM_ARCH_TEGRA_PWM_H */ 76