Lines Matching +full:pin +full:- +full:val

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mxl111sf-gpio.c - driver for the MaxLinear MXL111SF
5 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
8 #include "mxl111sf-gpio.h"
9 #include "mxl111sf-i2c.h"
12 /* ------------------------------------------------------------------------- */
22 static int mxl111sf_set_gpo_state(struct mxl111sf_state *state, u8 pin, u8 val) in mxl111sf_set_gpo_state() argument
27 mxl_debug_adv("(%d, %d)", pin, val); in mxl111sf_set_gpo_state()
29 if ((pin > 0) && (pin < 8)) { in mxl111sf_set_gpo_state()
33 tmp &= ~(1 << (pin - 1)); in mxl111sf_set_gpo_state()
34 tmp |= (val << (pin - 1)); in mxl111sf_set_gpo_state()
38 } else if (pin <= 10) { in mxl111sf_set_gpo_state()
39 if (pin == 0) in mxl111sf_set_gpo_state()
40 pin += 7; in mxl111sf_set_gpo_state()
44 tmp &= ~(1 << (pin - 3)); in mxl111sf_set_gpo_state()
45 tmp |= (val << (pin - 3)); in mxl111sf_set_gpo_state()
50 ret = -EINVAL; in mxl111sf_set_gpo_state()
55 static int mxl111sf_get_gpi_state(struct mxl111sf_state *state, u8 pin, u8 *val) in mxl111sf_get_gpi_state() argument
60 mxl_debug("(0x%02x)", pin); in mxl111sf_get_gpi_state()
62 *val = 0; in mxl111sf_get_gpi_state()
64 switch (pin) { in mxl111sf_get_gpi_state()
72 *val = (tmp >> (pin + 4)) & 0x01; in mxl111sf_get_gpi_state()
81 *val = (tmp >> pin) & 0x01; in mxl111sf_get_gpi_state()
89 *val = (tmp >> (pin - 3)) & 0x01; in mxl111sf_get_gpi_state()
92 return -EINVAL; /* invalid pin */ in mxl111sf_get_gpi_state()
99 u8 pin; member
101 u8 val; member
110 mxl_debug_adv("(%d, %d)", gpio_cfg->pin, gpio_cfg->dir); in mxl111sf_config_gpio_pins()
112 switch (gpio_cfg->pin) { in mxl111sf_config_gpio_pins()
120 tmp &= ~(1 << (gpio_cfg->pin + 4)); in mxl111sf_config_gpio_pins()
121 tmp |= (gpio_cfg->dir << (gpio_cfg->pin + 4)); in mxl111sf_config_gpio_pins()
133 tmp &= ~(1 << gpio_cfg->pin); in mxl111sf_config_gpio_pins()
134 tmp |= (gpio_cfg->dir << gpio_cfg->pin); in mxl111sf_config_gpio_pins()
145 tmp &= ~(1 << (gpio_cfg->pin - 3)); in mxl111sf_config_gpio_pins()
146 tmp |= (gpio_cfg->dir << (gpio_cfg->pin - 3)); in mxl111sf_config_gpio_pins()
152 return -EINVAL; /* invalid pin */ in mxl111sf_config_gpio_pins()
155 ret = (MXL_GPIO_DIR_OUTPUT == gpio_cfg->dir) ? in mxl111sf_config_gpio_pins()
157 gpio_cfg->pin, gpio_cfg->val) : in mxl111sf_config_gpio_pins()
159 gpio_cfg->pin, &gpio_cfg->val); in mxl111sf_config_gpio_pins()
166 int gpio, int direction, int val) in mxl111sf_hw_do_set_gpio() argument
169 .pin = gpio, in mxl111sf_hw_do_set_gpio()
171 .val = val, in mxl111sf_hw_do_set_gpio()
174 mxl_debug("(%d, %d, %d)", gpio, direction, val); in mxl111sf_hw_do_set_gpio()
179 /* ------------------------------------------------------------------------- */
546 /* ------------------------------------------------------------------------- */
548 static int mxl111sf_hw_set_gpio(struct mxl111sf_state *state, int gpio, int val) in mxl111sf_hw_set_gpio() argument
550 return mxl111sf_hw_do_set_gpio(state, gpio, MXL_GPIO_DIR_OUTPUT, val); in mxl111sf_hw_set_gpio()
570 static int pca9534_set_gpio(struct mxl111sf_state *state, int gpio, int val) in pca9534_set_gpio() argument
581 mxl_debug("(%d, %d)", gpio, val); in pca9534_set_gpio()
583 /* read current GPIO levels from flip-flop */ in pca9534_set_gpio()
584 i2c_transfer(&state->d->i2c_adap, msg, 2); in pca9534_set_gpio()
597 w[1] |= ((val ? 1 : 0) << gpio); in pca9534_set_gpio()
599 /* write new GPIO levels to flip-flop */ in pca9534_set_gpio()
600 i2c_transfer(&state->d->i2c_adap, &msg[0], 1); in pca9534_set_gpio()
616 i2c_transfer(&state->d->i2c_adap, &msg, 1); in pca9534_init_port_expander()
622 i2c_transfer(&state->d->i2c_adap, &msg, 1); in pca9534_init_port_expander()
627 int mxl111sf_set_gpio(struct mxl111sf_state *state, int gpio, int val) in mxl111sf_set_gpio() argument
629 mxl_debug("(%d, %d)", gpio, val); in mxl111sf_set_gpio()
631 switch (state->gpio_port_expander) { in mxl111sf_set_gpio()
637 return pca9534_set_gpio(state, gpio, val); in mxl111sf_set_gpio()
639 return mxl111sf_hw_set_gpio(state, gpio, val); in mxl111sf_set_gpio()
658 /* read current GPIO levels from flip-flop */ in mxl111sf_probe_port_expander()
659 ret = i2c_transfer(&state->d->i2c_adap, msg, 2); in mxl111sf_probe_port_expander()
661 state->port_expander_addr = msg[0].addr; in mxl111sf_probe_port_expander()
662 state->gpio_port_expander = mxl111sf_PCA9534; in mxl111sf_probe_port_expander()
664 state->port_expander_addr); in mxl111sf_probe_port_expander()
671 ret = i2c_transfer(&state->d->i2c_adap, msg, 2); in mxl111sf_probe_port_expander()
673 state->port_expander_addr = msg[0].addr; in mxl111sf_probe_port_expander()
674 state->gpio_port_expander = mxl111sf_PCA9534; in mxl111sf_probe_port_expander()
676 state->port_expander_addr); in mxl111sf_probe_port_expander()
679 state->port_expander_addr = 0xff; in mxl111sf_probe_port_expander()
680 state->gpio_port_expander = mxl111sf_gpio_hw; in mxl111sf_probe_port_expander()
689 if (0x00 == state->port_expander_addr) in mxl111sf_init_port_expander()
692 switch (state->gpio_port_expander) { in mxl111sf_init_port_expander()
704 /* ------------------------------------------------------------------------ */
709 * 3 - ATSC/MH# | 1 = ATSC transport, 0 = MH transport | default 0 in mxl111sf_gpio_mode_switch()
710 * 4 - ATSC_RST## | 1 = ATSC enable, 0 = ATSC Reset | default 0 in mxl111sf_gpio_mode_switch()
711 * 5 - ATSC_EN | 1 = ATSC power enable, 0 = ATSC power off | default 0 in mxl111sf_gpio_mode_switch()
712 * 6 - MH_RESET# | 1 = MH enable, 0 = MH Reset | default 0 in mxl111sf_gpio_mode_switch()
713 * 7 - MH_EN | 1 = MH power enable, 0 = MH power off | default 0 in mxl111sf_gpio_mode_switch()