static int ricoh61x_gpio_input(struct gpio_chip *gc, unsigned offset) { struct ricoh61x *ricoh61x = container_of(gc, struct ricoh61x, gpio_chip); return ricoh61x_clr_bits(ricoh61x->dev, RICOH61x_GPIO_IOSEL, 1 << offset); }
static void ricoh61x_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { struct ricoh61x *ricoh61x = container_of(gc, struct ricoh61x, gpio_chip); if (value) ricoh61x_set_bits(ricoh61x->dev, RICOH61x_GPIO_IOOUT, 1 << offset); else ricoh61x_clr_bits(ricoh61x->dev, RICOH61x_GPIO_IOOUT, 1 << offset); }
int ricoh61x_regulator_disable_eco_mode(struct regulator_dev *rdev) { struct ricoh61x_regulator *ri = rdev_get_drvdata(rdev); struct device *parent = to_ricoh61x_dev(rdev); int ret; ret = ricoh61x_clr_bits(parent, ri->eco_reg, (1 << ri->eco_bit)); if (ret < 0) dev_err(&rdev->dev, "Error Disable LDO eco mode\n"); return ret; }
static int ricoh61x_reg_disable(struct regulator_dev *rdev) { struct ricoh61x_regulator *ri = rdev_get_drvdata(rdev); struct device *parent = to_ricoh61x_dev(rdev); int ret = 0; ret = ricoh61x_clr_bits(parent, ri->reg_en_reg, (1 << ri->en_bit)); if (ret < 0) dev_err(&rdev->dev, "Error in updating the STATE register\n"); return ret; }
static int ricoh61x_regulator_preinit(struct device *parent, struct ricoh61x_regulator *ri, struct ricoh619_regulator_platform_data *ricoh61x_pdata) { int ret = 0; if (!ricoh61x_pdata->init_apply) return 0; if (ricoh61x_pdata->init_uV >= 0) { ret = __ricoh61x_set_s_voltage(parent, ri, ricoh61x_pdata->sleep_uV, ricoh61x_pdata->sleep_uV); if (ret < 0) { dev_err(ri->dev, "Not able to initialize voltage %d " "for rail %d err %d\n", ricoh61x_pdata->sleep_uV, ri->desc.id, ret); return ret; } ret = __ricoh61x_set_voltage(parent, ri, ricoh61x_pdata->init_uV, ricoh61x_pdata->init_uV, 0); if (ret < 0) { dev_err(ri->dev, "Not able to initialize voltage %d " "for rail %d err %d\n", ricoh61x_pdata->init_uV, ri->desc.id, ret); return ret; } } if (ricoh61x_pdata->init_enable) ret = ricoh61x_set_bits(parent, ri->reg_en_reg, (1 << ri->en_bit)); else ret = ricoh61x_clr_bits(parent, ri->reg_en_reg, (1 << ri->en_bit)); if (ret < 0) dev_err(ri->dev, "Not able to %s rail %d err %d\n", (ricoh61x_pdata->init_enable) ? "enable" : "disable", ri->desc.id, ret); return ret; }
static void ricoh61x_gpio_init(struct ricoh61x *ricoh61x, struct ricoh619_platform_data *pdata) { int ret; int i; struct ricoh619_gpio_init_data *ginit; if (pdata->gpio_base <= 0) return; for (i = 0; i < pdata->num_gpioinit_data; ++i) { ginit = &pdata->gpio_init_data[i]; if (!ginit->init_apply) continue; if (ginit->output_mode_en) { /* GPIO output mode */ if (ginit->output_val) /* output H */ ret = ricoh61x_set_bits(ricoh61x->dev, RICOH61x_GPIO_IOOUT, 1 << i); else /* output L */ ret = ricoh61x_clr_bits(ricoh61x->dev, RICOH61x_GPIO_IOOUT, 1 << i); if (!ret) ret = ricoh61x_set_bits(ricoh61x->dev, RICOH61x_GPIO_IOSEL, 1 << i); } else /* GPIO input mode */ ret = ricoh61x_clr_bits(ricoh61x->dev, RICOH61x_GPIO_IOSEL, 1 << i); /* if LED function enabled in OTP */ if (ginit->led_mode) { /* LED Mode 1 */ if (i == 0) /* GP0 */ ret = ricoh61x_set_bits(ricoh61x->dev, RICOH61x_GPIO_LED_FUNC, 0x04 | (ginit->led_func & 0x03)); if (i == 1) /* GP1 */ ret = ricoh61x_set_bits(ricoh61x->dev, RICOH61x_GPIO_LED_FUNC, 0x40 | (ginit->led_func & 0x03) << 4); } if (ret < 0) dev_err(ricoh61x->dev, "Gpio %d init " "dir configuration failed: %d\n", i, ret); } ricoh61x->gpio_chip.owner = THIS_MODULE; ricoh61x->gpio_chip.label = ricoh61x->client->name; ricoh61x->gpio_chip.dev = ricoh61x->dev; ricoh61x->gpio_chip.base = pdata->gpio_base; ricoh61x->gpio_chip.ngpio = RICOH61x_NR_GPIO; ricoh61x->gpio_chip.can_sleep = 1; ricoh61x->gpio_chip.direction_input = ricoh61x_gpio_input; ricoh61x->gpio_chip.direction_output = ricoh61x_gpio_output; ricoh61x->gpio_chip.set = ricoh61x_gpio_set; ricoh61x->gpio_chip.get = ricoh61x_gpio_get; ricoh61x->gpio_chip.to_irq = ricoh61x_gpio_to_irq; ret = gpiochip_add(&ricoh61x->gpio_chip); if (ret) dev_warn(ricoh61x->dev, "GPIO registration failed: %d\n", ret); }