diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2015-11-30 16:30:59 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-12-04 01:20:33 -0800 |
commit | 743a9ea7cd39dffc4f1dc104803f767ba774372b (patch) | |
tree | a31b89a803f213a2421cbef449fff19cae5c5f5e | |
parent | 6b75bfee7e66ff2061b3ca114ec52fada16af731 (diff) | |
download | chrome-ec-743a9ea7cd39dffc4f1dc104803f767ba774372b.tar.gz |
pwm: Add common initialization for PWM pins
Rather than having various PWM module groups initialized from various
HOOK_INIT functions, group them all into a single module and initialize
them all from a common function in pwm.c.
BUG=chromium:563708
TEST=Manual on samus / samus_pd (with CONFIG_ADC enabled). Verify that
samus fan + KB backlight control is functional and samus_pd correctly
sets PWM output.
BRANCH=None
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I9f9b09bfa544cd9bc6b7a867e77757dff0505941
Reviewed-on: https://chromium-review.googlesource.com/314882
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r-- | board/auron/gpio.inc | 2 | ||||
-rw-r--r-- | board/big/board.c | 3 | ||||
-rw-r--r-- | board/big/gpio.inc | 1 | ||||
-rw-r--r-- | board/chell/gpio.inc | 2 | ||||
-rw-r--r-- | board/it8380dev/gpio.inc | 4 | ||||
-rw-r--r-- | board/kunimitsu/gpio.inc | 4 | ||||
-rw-r--r-- | board/lars/gpio.inc | 4 | ||||
-rw-r--r-- | board/npcx_evb/gpio.inc | 8 | ||||
-rw-r--r-- | board/npcx_evb_arm/gpio.inc | 8 | ||||
-rw-r--r-- | board/rambi/gpio.inc | 2 | ||||
-rw-r--r-- | board/rambi/led.c | 3 | ||||
-rw-r--r-- | board/samus/gpio.inc | 4 | ||||
-rw-r--r-- | board/samus_pd/board.c | 7 | ||||
-rw-r--r-- | board/samus_pd/gpio.inc | 4 | ||||
-rw-r--r-- | board/strago/gpio.inc | 4 | ||||
-rw-r--r-- | board/strago/led.c | 3 | ||||
-rw-r--r-- | chip/npcx/fan.c | 3 | ||||
-rw-r--r-- | chip/stm32/pwm.c | 10 | ||||
-rw-r--r-- | chip/stm32/pwm_chip.h | 4 | ||||
-rw-r--r-- | chip/stm32/registers.h | 1 | ||||
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/fan.c | 2 | ||||
-rw-r--r-- | common/pwm.c | 12 | ||||
-rw-r--r-- | common/pwm_kblight.c | 3 | ||||
-rw-r--r-- | include/module_id.h | 16 |
25 files changed, 52 insertions, 64 deletions
diff --git a/board/auron/gpio.inc b/board/auron/gpio.inc index 0cbd553a5a..d27cc66230 100644 --- a/board/auron/gpio.inc +++ b/board/auron/gpio.inc @@ -98,4 +98,4 @@ ALTERNATE(PIN_MASK(J, 0x40), 1, MODULE_PECI, 0) /* PECI Tx */ ALTERNATE(PIN_MASK(J, 0x80), 0, MODULE_PECI, GPIO_ANALOG) /* PECI Rx */ ALTERNATE(PIN_MASK(L, 0x3f), 15, MODULE_LPC, 0) /* LPC */ ALTERNATE(PIN_MASK(M, 0x33), 15, MODULE_LPC, 0) /* LPC */ -ALTERNATE(PIN_MASK(N, 0x0c), 1, MODULE_PWM_FAN, 0) /* FAN0PWM2 */ +ALTERNATE(PIN_MASK(N, 0x0c), 1, MODULE_PWM, 0) /* FAN0PWM2 */ diff --git a/board/big/board.c b/board/big/board.c index 54fd88d12e..037b115585 100644 --- a/board/big/board.c +++ b/board/big/board.c @@ -44,7 +44,6 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); /* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - {STM32_TIM(2), STM32_TIM_CH(3), - PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, + {STM32_TIM(2), STM32_TIM_CH(3), PWM_CONFIG_ACTIVE_LOW}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/big/gpio.inc b/board/big/gpio.inc index a5220d33ce..ad80c47030 100644 --- a/board/big/gpio.inc +++ b/board/big/gpio.inc @@ -57,6 +57,7 @@ GPIO(EC_BL_OVERRIDE, PIN(H, 1), GPIO_ODR_HIGH) GPIO(PMIC_THERM_L, PIN(A, 1), GPIO_ODR_HIGH) GPIO(PMIC_WARM_RESET_L, PIN(C, 3), GPIO_ODR_HIGH) +ALTERNATE(PIN_MASK(A, 0x0004), GPIO_ALT_TIM2, MODULE_PWM, GPIO_DEFAULT) ALTERNATE(PIN_MASK(A, 0x00f0), GPIO_ALT_SPI, MODULE_SPI, GPIO_DEFAULT) ALTERNATE(PIN_MASK(A, 0x0600), GPIO_ALT_USART, MODULE_UART, GPIO_DEFAULT) ALTERNATE(PIN_MASK(B, 0x00c0), GPIO_ALT_I2C, MODULE_I2C, GPIO_DEFAULT) diff --git a/board/chell/gpio.inc b/board/chell/gpio.inc index 6aab9278f6..74fb4b0414 100644 --- a/board/chell/gpio.inc +++ b/board/chell/gpio.inc @@ -118,7 +118,7 @@ ALTERNATE(PIN_MASK(12, 0x60), 2, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) /* KB COL - GPIO142, GPIO144 */ ALTERNATE(PIN_MASK(14, 0x14), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) /* Keyboard Backlight PWM - GPIO34 */ -ALTERNATE(PIN_MASK(3, 0x10), 1, MODULE_PWM_KBLIGHT, 0) +ALTERNATE(PIN_MASK(3, 0x10), 1, MODULE_PWM, 0) /* LPC pins */ /* LPC_CLK_RUN_L - GPIO014 */ diff --git a/board/it8380dev/gpio.inc b/board/it8380dev/gpio.inc index 49a5929f06..e438771a58 100644 --- a/board/it8380dev/gpio.inc +++ b/board/it8380dev/gpio.inc @@ -49,8 +49,8 @@ ALTERNATE(PIN_MASK(A, 0x40), 3, MODULE_SPI, 0) /* SSCK of SPI */ ALTERNATE(PIN_MASK(C, 0x28), 3, MODULE_SPI, 0) /* SMOSI/SMISO of SPI */ ALTERNATE(PIN_MASK(G, 0x01), 3, MODULE_SPI, 0) /* SSCE1# of SPI */ ALTERNATE(PIN_MASK(G, 0x04), 3, MODULE_SPI, 0) /* SSCE0# of SPI */ -ALTERNATE(PIN_MASK(A, 0x80), 1, MODULE_PWM_FAN, 0) /* PWM7 for FAN1 */ -ALTERNATE(PIN_MASK(D, 0x40), 3, MODULE_PWM_FAN, 0) /* TACH0A for FAN1 */ +ALTERNATE(PIN_MASK(A, 0x80), 1, MODULE_PWM, 0) /* PWM7 for FAN1 */ +ALTERNATE(PIN_MASK(D, 0x40), 3, MODULE_PWM, 0) /* TACH0A for FAN1 */ ALTERNATE(PIN_MASK(B, 0x18), 1, MODULE_I2C, 0) /* I2C A SCL/SDA */ #ifdef CONFIG_IT83XX_SMCLK2_ON_GPC7 ALTERNATE(PIN_MASK(C, 0x86), 1, MODULE_I2C, 0) /* I2C B SCL/SDA, C SCL */ diff --git a/board/kunimitsu/gpio.inc b/board/kunimitsu/gpio.inc index 74e9b5cc89..b62aa978ea 100644 --- a/board/kunimitsu/gpio.inc +++ b/board/kunimitsu/gpio.inc @@ -158,6 +158,6 @@ ALTERNATE(PIN_MASK(12, 0x02), 1, MODULE_PMU, 0) /* RPM-PWM for FAN */ /* TACH2PWM_OUT - GPIO34 */ -ALTERNATE(PIN_MASK(3, 0x10), 3, MODULE_PWM_FAN, 0) +ALTERNATE(PIN_MASK(3, 0x10), 3, MODULE_PWM, 0) /* TACH2PWM_IN - GPIO140 */ -ALTERNATE(PIN_MASK(14, 0x01), 3, MODULE_PWM_FAN, 0) +ALTERNATE(PIN_MASK(14, 0x01), 3, MODULE_PWM, 0) diff --git a/board/lars/gpio.inc b/board/lars/gpio.inc index cc7df2a161..529b3c0ff8 100644 --- a/board/lars/gpio.inc +++ b/board/lars/gpio.inc @@ -136,9 +136,9 @@ ALTERNATE(PIN_MASK(16, 0x24), 1, MODULE_UART, 0) /* RPM-PWM for FAN */ /* TACH2PWM_IN - GPIO140 */ -ALTERNATE(PIN_MASK(14, 0x01), 3, MODULE_PWM_FAN, 0) +ALTERNATE(PIN_MASK(14, 0x01), 3, MODULE_PWM, 0) /* TACH2PWM_OUT - GPIO034 */ -ALTERNATE(PIN_MASK(3, 0x10), 3, MODULE_PWM_FAN, 0) +ALTERNATE(PIN_MASK(3, 0x10), 3, MODULE_PWM, 0) /* ADC pins */ /* ADC1 - GPIO057 / PPVAR_BOOSTIN_SENSE */ diff --git a/board/npcx_evb/gpio.inc b/board/npcx_evb/gpio.inc index 027855620b..526960ca1b 100644 --- a/board/npcx_evb/gpio.inc +++ b/board/npcx_evb/gpio.inc @@ -61,13 +61,13 @@ ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* I2C3SDA/I2C3SCL ALTERNATE(PIN_MASK(4, 0x38), 1, MODULE_ADC, 0) /* ADC GPIO45/44/43 */ ALTERNATE(PIN_MASK(A, 0x0A), 1, MODULE_SPI, 0) /* SPIP_MOSI/SPIP_SCLK GPIOA3/A1 */ ALTERNATE(PIN_MASK(9, 0x20), 1, MODULE_SPI, 0) /* SPIP_MISO GPIO95 */ -ALTERNATE(PIN_MASK(C, 0x04), 3, MODULE_PWM_KBLIGHT, 0) /* PWM1 for PWM/KBLIGHT Test GPIOC2 */ +ALTERNATE(PIN_MASK(C, 0x04), 3, MODULE_PWM, 0) /* PWM1 for PWM/KBLIGHT Test GPIOC2 */ /* Alternative functionality for FANS */ #ifdef CONFIG_FANS -ALTERNATE(PIN_MASK(C, 0x08), 7, MODULE_PWM_FAN, 0) /* PWM0 for PWM/FAN Test GPIOC3 */ +ALTERNATE(PIN_MASK(C, 0x08), 7, MODULE_PWM, 0) /* PWM0 for PWM/FAN Test GPIOC3 */ #if NPCX_TACH_SEL2 -ALTERNATE(PIN_MASK(9, 0x08), 3, MODULE_PWM_FAN, 0) /* MFT-1/TA1_TACH1 for FAN GPIO93 */ +ALTERNATE(PIN_MASK(9, 0x08), 3, MODULE_PWM, 0) /* MFT-1/TA1_TACH1 for FAN GPIO93 */ #else -ALTERNATE(PIN_MASK(4, 0x01), 3, MODULE_PWM_FAN, 0) /* MFT-1/TA1_TACH1 for FAN Test GPIO40 */ +ALTERNATE(PIN_MASK(4, 0x01), 3, MODULE_PWM, 0) /* MFT-1/TA1_TACH1 for FAN Test GPIO40 */ #endif #endif diff --git a/board/npcx_evb_arm/gpio.inc b/board/npcx_evb_arm/gpio.inc index 1d1667ba06..323edb916e 100644 --- a/board/npcx_evb_arm/gpio.inc +++ b/board/npcx_evb_arm/gpio.inc @@ -62,13 +62,13 @@ ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* I2C3SDA/I2C3SCL ALTERNATE(PIN_MASK(4, 0x38), 1, MODULE_ADC, 0) /* ADC GPIO45/44/43 */ ALTERNATE(PIN_MASK(A, 0x0A), 1, MODULE_SPI, 0) /* SPIP_MOSI/SPIP_SCLK GPIOA3/A1 */ ALTERNATE(PIN_MASK(9, 0x20), 1, MODULE_SPI, 0) /* SPIP_MISO GPIO95 */ -ALTERNATE(PIN_MASK(C, 0x04), 3, MODULE_PWM_KBLIGHT, 0) /* PWM1 for PWM/KBLIGHT Test GPIOC2 */ +ALTERNATE(PIN_MASK(C, 0x04), 3, MODULE_PWM, 0) /* PWM1 for PWM/KBLIGHT Test GPIOC2 */ /* Alternative functionality for FANS */ #ifdef CONFIG_FANS -ALTERNATE(PIN_MASK(C, 0x08), 7, MODULE_PWM_FAN, 0) /* PWM0 for PWM/FAN Test GPIOC3 */ +ALTERNATE(PIN_MASK(C, 0x08), 7, MODULE_PWM, 0) /* PWM0 for PWM/FAN Test GPIOC3 */ #if NPCX_TACH_SEL2 -ALTERNATE(PIN_MASK(9, 0x08), 3, MODULE_PWM_FAN, 0) /* MFT-1/TA1_TACH1 for FAN GPIO93 */ +ALTERNATE(PIN_MASK(9, 0x08), 3, MODULE_PWM, 0) /* MFT-1/TA1_TACH1 for FAN GPIO93 */ #else -ALTERNATE(PIN_MASK(4, 0x01), 3, MODULE_PWM_FAN, 0) /* MFT-1/TA1_TACH1 for FAN Test GPIO40 */ +ALTERNATE(PIN_MASK(4, 0x01), 3, MODULE_PWM, 0) /* MFT-1/TA1_TACH1 for FAN Test GPIO40 */ #endif #endif diff --git a/board/rambi/gpio.inc b/board/rambi/gpio.inc index a4fdf129b6..190c2a9374 100644 --- a/board/rambi/gpio.inc +++ b/board/rambi/gpio.inc @@ -74,4 +74,4 @@ ALTERNATE(PIN_MASK(B, 0x80), 3, MODULE_I2C, GPIO_OPEN_DRAIN) /* I2C5 SDA */ ALTERNATE(PIN_MASK(D, 0x0f), 2, MODULE_SPI, 0) /* SPI1 */ ALTERNATE(PIN_MASK(L, 0x3f), 15, MODULE_LPC, 0) /* LPC */ ALTERNATE(PIN_MASK(M, 0x21), 15, MODULE_LPC, 0) /* LPC */ -ALTERNATE(PIN_MASK(N, 0x50), 1, MODULE_PWM_LED, GPIO_OPEN_DRAIN) /* FAN0PWM 3&4 */ +ALTERNATE(PIN_MASK(N, 0x50), 1, MODULE_PWM, GPIO_OPEN_DRAIN) /* FAN0PWM 3&4 */ diff --git a/board/rambi/led.c b/board/rambi/led.c index 5e3e2edb37..74cfd5a18e 100644 --- a/board/rambi/led.c +++ b/board/rambi/led.c @@ -62,9 +62,6 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) static void led_init(void) { - /* Configure GPIOs */ - gpio_config_module(MODULE_PWM_LED, 1); - /* * Enable PWMs and set to 0% duty cycle. If they're disabled, the LM4 * seems to ground the pins instead of letting them float. diff --git a/board/samus/gpio.inc b/board/samus/gpio.inc index 969f3f072d..ade6967437 100644 --- a/board/samus/gpio.inc +++ b/board/samus/gpio.inc @@ -116,5 +116,5 @@ ALTERNATE(PIN_MASK(M, 0x33), 15, MODULE_LPC, 0) /* LPC */ ALTERNATE(PIN_MASK(M, 0x04), 15, MODULE_LPC, GPIO_OPEN_DRAIN) /* LPC */ #endif -ALTERNATE(PIN_MASK(N, 0x3c), 1, MODULE_PWM_FAN, 0) /* FAN0PWM 2&3 */ -ALTERNATE(PIN_MASK(N, 0x40), 1, MODULE_PWM_KBLIGHT, 0) /* FAN0PWM4 */ +ALTERNATE(PIN_MASK(N, 0x3c), 1, MODULE_PWM, 0) /* FAN0PWM 2&3 */ +ALTERNATE(PIN_MASK(N, 0x40), 1, MODULE_PWM, 0) /* FAN0PWM4 */ diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index 61159dc3c4..7a0c0a759b 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -62,7 +62,7 @@ static int desired_charge_rate_ma = -1; /* PWM channels. Must be in the exact same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - {STM32_TIM(15), STM32_TIM_CH(2), 0, GPIO_ILIM_ADJ_PWM, GPIO_ALT_F1}, + {STM32_TIM(15), STM32_TIM_CH(2), 0}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); @@ -475,6 +475,9 @@ int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state) static int board_update_charge_limit(int charge_ma) { +#ifdef CONFIG_PWM + int pwm_duty; +#endif static int actual_charge_rate_ma = -1; desired_charge_rate_ma = charge_ma; @@ -490,7 +493,7 @@ static int board_update_charge_limit(int charge_ma) actual_charge_rate_ma = charge_ma; #ifdef CONFIG_PWM - int pwm_duty = MA_TO_PWM(charge_ma); + pwm_duty = MA_TO_PWM(charge_ma); if (pwm_duty < 0) pwm_duty = 0; else if (pwm_duty > 100) diff --git a/board/samus_pd/gpio.inc b/board/samus_pd/gpio.inc index 407e073a5f..779519fe5c 100644 --- a/board/samus_pd/gpio.inc +++ b/board/samus_pd/gpio.inc @@ -128,3 +128,7 @@ ALTERNATE(PIN_MASK(A, 0x0600), 1, MODULE_UART, 0) /* USART1: PA9/PA10 */ ALTERNATE(PIN_MASK(D, 0x0060), 0, MODULE_UART, 0) /* USART2: PD5/PD6 */ ALTERNATE(PIN_MASK(C, 0x0030), 1, MODULE_UART, 0) /* USART3: PC4/PC5 */ ALTERNATE(PIN_MASK(B, 0x0cc0), 1, MODULE_I2C, 0) /* I2C SLAVE:PB6/7 MASTER:PB10/11 */ + +#ifdef CONFIG_PWM +ALTERNATE(PIN_MASK(B, 0x8000), 1, MODULE_PWM, 0) /* ILIM_PWM: PB15 */ +#endif diff --git a/board/strago/gpio.inc b/board/strago/gpio.inc index 016d687401..9eaf13e783 100644 --- a/board/strago/gpio.inc +++ b/board/strago/gpio.inc @@ -135,8 +135,8 @@ ALTERNATE(PIN_MASK(5, 0x10), 1, MODULE_SPI, 0) ALTERNATE(PIN_MASK(16, 0x10), 1, MODULE_SPI, 0) ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0) /* 153: CLK */ -ALTERNATE(PIN_MASK(13, 0x48), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 133: PWM0, 136: PWM1 */ -ALTERNATE(PIN_MASK(14, 0x02), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 141: PWM3 */ +ALTERNATE(PIN_MASK(13, 0x48), 1, MODULE_PWM, GPIO_OUTPUT) /* 133: PWM0, 136: PWM1 */ +ALTERNATE(PIN_MASK(14, 0x02), 1, MODULE_PWM, GPIO_OUTPUT) /* 141: PWM3 */ ALTERNATE(PIN_MASK(5, 0x40), 1, MODULE_ADC, 0) /* 56: temperature sensor 1 */ ALTERNATE(PIN_MASK(6, 0x01), 1, MODULE_ADC, 0) /* 60: PC_MON, 62: temperature sensor 3 */ diff --git a/board/strago/led.c b/board/strago/led.c index 74c5da3598..3549e09c11 100644 --- a/board/strago/led.c +++ b/board/strago/led.c @@ -129,9 +129,6 @@ static void strago_led_set_battery(void) static void led_init(void) { - /* Configure GPIOs */ - gpio_config_module(MODULE_PWM_LED, 1); - /* * Enable PWMs and set to 0% duty cycle. If they're disabled, * seems to ground the pins instead of letting them float. diff --git a/chip/npcx/fan.c b/chip/npcx/fan.c index 6b4e24685a..11fefe6429 100644 --- a/chip/npcx/fan.c +++ b/chip/npcx/fan.c @@ -170,9 +170,6 @@ static void fan_config(int ch, int enable_mft_read_rpm) enum npcx_mft_clk_src clk_src = mft_channels[ch].clk_src; volatile struct fan_status_t *p_status = fan_status + ch; - /* Configure pins from GPIOs to FAN */ - gpio_config_module(MODULE_PWM_FAN, 1); - /* Setup pwm with fan spec. */ pwm_config(pwm_id); diff --git a/chip/stm32/pwm.c b/chip/stm32/pwm.c index 577e984498..a457cb709d 100644 --- a/chip/stm32/pwm.c +++ b/chip/stm32/pwm.c @@ -35,22 +35,12 @@ int pwm_get_duty(enum pwm_channel ch) static void pwm_configure(enum pwm_channel ch) { const struct pwm_t *pwm = pwm_channels + ch; - const struct gpio_info *gpio = gpio_list + pwm->pin; timer_ctlr_t *tim = (timer_ctlr_t *)(pwm->tim.base); volatile unsigned *ccmr = NULL; if (using_pwm[ch]) return; -#if defined(CHIP_FAMILY_STM32F0) || defined(CHIP_FAMILY_STM32F3) - gpio_set_alternate_function(gpio->port, gpio->mask, pwm->gpio_alt_func); -#elif defined(CHIP_FAMILY_STM32L) - gpio_set_alternate_function(gpio->port, gpio->mask, - GPIO_ALT_TIM(pwm->tim.id)); -#else -#error "GPIO alternate function selection not implemented for chip family." -#endif - /* Enable timer */ __hw_timer_enable_clock(pwm->tim.id, 1); diff --git a/chip/stm32/pwm_chip.h b/chip/stm32/pwm_chip.h index ac30f645ee..418c7417fe 100644 --- a/chip/stm32/pwm_chip.h +++ b/chip/stm32/pwm_chip.h @@ -22,10 +22,6 @@ struct pwm_t { int channel; /* PWM channel flags. See include/pwm.h */ uint32_t flags; - /* GPIO pin corresponding to the PWM channel */ - enum gpio_signal pin; - /* GPIO alternate function - only needed for STM32F0 family */ - int gpio_alt_func; }; extern const struct pwm_t pwm_channels[]; diff --git a/chip/stm32/registers.h b/chip/stm32/registers.h index a435a10173..9352584d28 100644 --- a/chip/stm32/registers.h +++ b/chip/stm32/registers.h @@ -344,7 +344,6 @@ typedef volatile struct timer_ctlr timer_ctlr_t; #define GPIO_ALT_TIM2 0x1 #define GPIO_ALT_TIM3_4 0x2 #define GPIO_ALT_TIM9_11 0x3 -#define GPIO_ALT_TIM(x) (((x) > 5) ? 0x3 : ((x) / 3 + 1)) #define GPIO_ALT_I2C 0x4 #define GPIO_ALT_SPI 0x5 #define GPIO_ALT_USART 0x7 diff --git a/common/build.mk b/common/build.mk index c7fd49a5f1..01b0868917 100644 --- a/common/build.mk +++ b/common/build.mk @@ -40,7 +40,7 @@ common-$(CONFIG_COMMON_TIMER)+=timer.o common-$(CONFIG_CRC8)+= crc8.o common-$(CONFIG_EXTENSION_COMMAND)+=extension.o common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o -common-$(CONFIG_FANS)+=fan.o +common-$(CONFIG_FANS)+=fan.o pwm.o common-$(CONFIG_FLASH)+=flash.o common-$(CONFIG_FMAP)+=fmap.o common-$(CONFIG_GESTURE_SW_DETECTION)+=gesture.o diff --git a/common/fan.c b/common/fan.c index 86cdafe814..b3f4428af0 100644 --- a/common/fan.c +++ b/common/fan.c @@ -439,8 +439,6 @@ static void pwm_fan_init(void) int i; int fan = 0; - gpio_config_module(MODULE_PWM_FAN, 1); - for (fan = 0; fan < CONFIG_FANS; fan++) fan_channel_setup(fans[fan].ch, fans[fan].flags); diff --git a/common/pwm.c b/common/pwm.c index 3a3073d142..7377d1d170 100644 --- a/common/pwm.c +++ b/common/pwm.c @@ -5,9 +5,12 @@ #include "common.h" #include "console.h" +#include "gpio.h" +#include "hooks.h" #include "pwm.h" #include "util.h" +#ifdef CONFIG_PWM /** * Print status of a PWM channel. * @@ -61,3 +64,12 @@ DECLARE_CONSOLE_COMMAND(pwmduty, cc_pwm_duty, "[channel [<percent> | -1=disable]]", "Get/set PWM duty cycles ", NULL); +#endif /* CONFIG_PWM */ + +/* Initialize all PWM pins as functional */ +static void pwm_pin_init(void) +{ + gpio_config_module(MODULE_PWM, 1); +} +/* HOOK_PRIO_INIT_PWM may be used for chip PWM unit init, so use PRIO + 1 */ +DECLARE_HOOK(HOOK_INIT, pwm_pin_init, HOOK_PRIO_INIT_PWM + 1); diff --git a/common/pwm_kblight.c b/common/pwm_kblight.c index 5f84dd66af..15a2feb2bc 100644 --- a/common/pwm_kblight.c +++ b/common/pwm_kblight.c @@ -81,9 +81,6 @@ static void pwm_kblight_init(void) const struct pwm_kbd_state *prev; int version, size; - /* Configure GPIO */ - gpio_config_module(MODULE_PWM_KBLIGHT, 1); - prev = (const struct pwm_kbd_state *) system_get_jump_tag(PWMKBD_SYSJUMP_TAG, &version, &size); if (prev && version == PWM_HOOK_VERSION && size == sizeof(*prev)) { diff --git a/include/module_id.h b/include/module_id.h index bc1ef0ab09..b4c1191a68 100644 --- a/include/module_id.h +++ b/include/module_id.h @@ -31,24 +31,22 @@ enum module_id { MODULE_PMU, MODULE_PORT80, MODULE_POWER_LED, - MODULE_PWM_FAN, /* 20 */ - MODULE_PWM_KBLIGHT, - MODULE_PWM_LED, + MODULE_PWM, /* 20 */ MODULE_SPI, MODULE_SPI_FLASH, - MODULE_SPI_MASTER, /* 25 */ + MODULE_SPI_MASTER, MODULE_SWITCH, - MODULE_SYSTEM, + MODULE_SYSTEM, /* 25 */ MODULE_TASK, MODULE_THERMAL, - MODULE_UART, /* 30 */ + MODULE_UART, MODULE_USART, - MODULE_USB, + MODULE_USB, /* 30 */ MODULE_USB_DEBUG, MODULE_USB_PD, - MODULE_USB_PORT_POWER, /* 35 */ + MODULE_USB_PORT_POWER, MODULE_USB_SWITCH, - MODULE_VBOOT, + MODULE_VBOOT, /* 35 */ /* Module count; not an actual module */ MODULE_COUNT |