Lines Matching refs:dev

70 static int stmfx_read(struct udevice *dev, uint offset)  in stmfx_read()  argument
72 return dm_i2c_reg_read(dev_get_parent(dev), offset); in stmfx_read()
75 static int stmfx_write(struct udevice *dev, uint offset, unsigned int val) in stmfx_write() argument
77 return dm_i2c_reg_write(dev_get_parent(dev), offset, val); in stmfx_write()
80 static int stmfx_read_reg(struct udevice *dev, u8 reg_base, uint offset) in stmfx_read_reg() argument
86 ret = stmfx_read(dev, reg); in stmfx_read_reg()
93 static int stmfx_write_reg(struct udevice *dev, u8 reg_base, uint offset, in stmfx_write_reg() argument
100 ret = stmfx_read(dev, reg); in stmfx_write_reg()
105 return stmfx_write(dev, reg, ret); in stmfx_write_reg()
108 static int stmfx_conf_set_pupd(struct udevice *dev, unsigned int offset, in stmfx_conf_set_pupd() argument
111 return stmfx_write_reg(dev, STMFX_REG_GPIO_PUPD, offset, pupd); in stmfx_conf_set_pupd()
114 static int stmfx_conf_get_pupd(struct udevice *dev, unsigned int offset) in stmfx_conf_get_pupd() argument
116 return stmfx_read_reg(dev, STMFX_REG_GPIO_PUPD, offset); in stmfx_conf_get_pupd()
119 static int stmfx_conf_set_type(struct udevice *dev, unsigned int offset, in stmfx_conf_set_type() argument
122 return stmfx_write_reg(dev, STMFX_REG_GPIO_TYPE, offset, type); in stmfx_conf_set_type()
125 static int stmfx_conf_get_type(struct udevice *dev, unsigned int offset) in stmfx_conf_get_type() argument
127 return stmfx_read_reg(dev, STMFX_REG_GPIO_TYPE, offset); in stmfx_conf_get_type()
130 static int stmfx_gpio_get(struct udevice *dev, unsigned int offset) in stmfx_gpio_get() argument
132 return stmfx_read_reg(dev, STMFX_REG_GPIO_STATE, offset); in stmfx_gpio_get()
135 static int stmfx_gpio_set(struct udevice *dev, unsigned int offset, int value) in stmfx_gpio_set() argument
140 return stmfx_write(dev, reg + get_reg(offset), mask); in stmfx_gpio_set()
143 static int stmfx_gpio_get_function(struct udevice *dev, unsigned int offset) in stmfx_gpio_get_function() argument
145 int ret = stmfx_read_reg(dev, STMFX_REG_GPIO_DIR, offset); in stmfx_gpio_get_function()
154 static int stmfx_gpio_direction_input(struct udevice *dev, unsigned int offset) in stmfx_gpio_direction_input() argument
156 return stmfx_write_reg(dev, STMFX_REG_GPIO_DIR, offset, 0); in stmfx_gpio_direction_input()
159 static int stmfx_gpio_direction_output(struct udevice *dev, in stmfx_gpio_direction_output() argument
162 int ret = stmfx_gpio_set(dev, offset, value); in stmfx_gpio_direction_output()
166 return stmfx_write_reg(dev, STMFX_REG_GPIO_DIR, offset, 1); in stmfx_gpio_direction_output()
169 static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, in stmfx_gpio_set_flags() argument
180 ret = stmfx_conf_set_type(dev, offset, 0); in stmfx_gpio_set_flags()
182 ret = stmfx_conf_set_type(dev, offset, 1); in stmfx_gpio_set_flags()
185 ret = stmfx_gpio_direction_output(dev, offset, value); in stmfx_gpio_set_flags()
187 ret = stmfx_gpio_direction_input(dev, offset); in stmfx_gpio_set_flags()
191 ret = stmfx_conf_set_type(dev, offset, 1); in stmfx_gpio_set_flags()
194 ret = stmfx_conf_set_pupd(dev, offset, 1); in stmfx_gpio_set_flags()
196 ret = stmfx_conf_set_type(dev, offset, 1); in stmfx_gpio_set_flags()
199 ret = stmfx_conf_set_pupd(dev, offset, 0); in stmfx_gpio_set_flags()
206 static int stmfx_gpio_get_flags(struct udevice *dev, unsigned int offset, in stmfx_gpio_get_flags() argument
212 if (stmfx_gpio_get_function(dev, offset) == GPIOF_OUTPUT) { in stmfx_gpio_get_flags()
214 ret = stmfx_conf_get_type(dev, offset); in stmfx_gpio_get_flags()
220 ret = stmfx_gpio_get(dev, offset); in stmfx_gpio_get_flags()
227 ret = stmfx_conf_get_type(dev, offset); in stmfx_gpio_get_flags()
231 ret = stmfx_conf_get_pupd(dev, offset); in stmfx_gpio_get_flags()
245 static int stmfx_gpio_probe(struct udevice *dev) in stmfx_gpio_probe() argument
247 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); in stmfx_gpio_probe()
253 if (!dev_read_phandle_with_args(dev, "gpio-ranges", in stmfx_gpio_probe()
262 stmfx_write(dev, STMFX_REG_SYS_CTRL, sys_ctrl); in stmfx_gpio_probe()
296 static int stmfx_pinctrl_conf_set(struct udevice *dev, unsigned int pin, in stmfx_pinctrl_conf_set() argument
300 struct stmfx_pinctrl *plat = dev_get_plat(dev); in stmfx_pinctrl_conf_set()
311 ret = stmfx_conf_set_type(dev, pin, 0); in stmfx_pinctrl_conf_set()
314 ret = stmfx_conf_set_type(dev, pin, 1); in stmfx_pinctrl_conf_set()
317 ret = stmfx_conf_set_pupd(dev, pin, 0); in stmfx_pinctrl_conf_set()
320 ret = stmfx_conf_set_type(dev, pin, 1); in stmfx_pinctrl_conf_set()
323 ret = stmfx_conf_set_pupd(dev, pin, 1); in stmfx_pinctrl_conf_set()
326 ret = stmfx_conf_set_type(dev, pin, 1); in stmfx_pinctrl_conf_set()
339 static int stmfx_pinctrl_get_pins_count(struct udevice *dev) in stmfx_pinctrl_get_pins_count() argument
341 struct stmfx_pinctrl *plat = dev_get_plat(dev); in stmfx_pinctrl_get_pins_count()
354 static const char *stmfx_pinctrl_get_pin_name(struct udevice *dev, in stmfx_pinctrl_get_pin_name() argument
364 static const char *stmfx_pinctrl_get_pin_conf(struct udevice *dev, in stmfx_pinctrl_get_pin_conf() argument
369 type = stmfx_conf_get_type(dev, pin); in stmfx_pinctrl_get_pin_conf()
382 pupd = stmfx_conf_get_pupd(dev, pin); in stmfx_pinctrl_get_pin_conf()
392 static int stmfx_pinctrl_get_pin_muxing(struct udevice *dev, in stmfx_pinctrl_get_pin_muxing() argument
396 struct stmfx_pinctrl *plat = dev_get_plat(dev); in stmfx_pinctrl_get_pin_muxing()
405 strncat(buf, stmfx_pinctrl_get_pin_conf(dev, selector, func), size); in stmfx_pinctrl_get_pin_muxing()
410 static int stmfx_pinctrl_bind(struct udevice *dev) in stmfx_pinctrl_bind() argument
412 struct stmfx_pinctrl *plat = dev_get_plat(dev); in stmfx_pinctrl_bind()
415 device_set_name(dev, dev->parent->name); in stmfx_pinctrl_bind()
417 return device_bind_driver_to_node(dev->parent, in stmfx_pinctrl_bind()
418 "stmfx-gpio", dev->parent->name, in stmfx_pinctrl_bind()
419 dev_ofnode(dev), &plat->gpio); in stmfx_pinctrl_bind()
422 static int stmfx_pinctrl_probe(struct udevice *dev) in stmfx_pinctrl_probe() argument
424 struct stmfx_pinctrl *plat = dev_get_plat(dev); in stmfx_pinctrl_probe()
455 static int stmfx_chip_init(struct udevice *dev) in stmfx_chip_init() argument
460 struct dm_i2c_chip *chip = dev_get_parent_plat(dev); in stmfx_chip_init()
462 ret = dm_i2c_reg_read(dev, STMFX_REG_CHIP_ID); in stmfx_chip_init()
464 dev_err(dev, "error reading chip id: %d\n", ret); in stmfx_chip_init()
480 dev_err(dev, "unknown chip id: %#x\n", id); in stmfx_chip_init()
484 ret = dm_i2c_read(dev, STMFX_REG_FW_VERSION_MSB, in stmfx_chip_init()
487 dev_err(dev, "error reading fw version: %d\n", ret); in stmfx_chip_init()
491 dev_info(dev, "STMFX id: %#x, fw version: %x.%02x\n", in stmfx_chip_init()
494 ret = dm_i2c_reg_read(dev, STMFX_REG_SYS_CTRL); in stmfx_chip_init()
499 ret = dm_i2c_reg_write(dev, STMFX_REG_SYS_CTRL, in stmfx_chip_init()
509 static int stmfx_probe(struct udevice *dev) in stmfx_probe() argument
514 ret = device_get_supply_regulator(dev, "vdd-supply", &vdd); in stmfx_probe()
516 dev_err(dev, "vdd regulator error:%d\n", ret); in stmfx_probe()
522 dev_err(dev, "vdd enable failed: %d\n", ret); in stmfx_probe()
527 return stmfx_chip_init(dev); in stmfx_probe()