--- zzzz-none-000/linux-3.10.107/drivers/mfd/htc-i2cpld.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/mfd/htc-i2cpld.c 2021-02-04 17:41:59.000000000 +0000 @@ -227,15 +227,12 @@ static void htcpld_chip_set(struct gpio_chip *chip, unsigned offset, int val) { struct i2c_client *client; - struct htcpld_chip *chip_data; + struct htcpld_chip *chip_data = + container_of(chip, struct htcpld_chip, chip_out); unsigned long flags; - chip_data = container_of(chip, struct htcpld_chip, chip_out); - if (!chip_data) - return; - client = chip_data->client; - if (client == NULL) + if (!client) return; spin_lock_irqsave(&chip_data->lock, flags); @@ -261,31 +258,18 @@ static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset) { struct htcpld_chip *chip_data; - int val = 0; - int is_input = 0; + u8 cache; - /* Try out first */ - chip_data = container_of(chip, struct htcpld_chip, chip_out); - if (!chip_data) { - /* Try in */ - is_input = 1; + if (!strncmp(chip->label, "htcpld-out", 10)) { + chip_data = container_of(chip, struct htcpld_chip, chip_out); + cache = chip_data->cache_out; + } else if (!strncmp(chip->label, "htcpld-in", 9)) { chip_data = container_of(chip, struct htcpld_chip, chip_in); - if (!chip_data) - return -EINVAL; - } - - /* Determine if this is an input or output GPIO */ - if (!is_input) - /* Use the output cache */ - val = (chip_data->cache_out >> offset) & 1; - else - /* Use the input cache */ - val = (chip_data->cache_in >> offset) & 1; + cache = chip_data->cache_in; + } else + return -EINVAL; - if (val) - return 1; - else - return 0; + return (cache >> offset) & 1; } static int htcpld_direction_output(struct gpio_chip *chip, @@ -332,18 +316,12 @@ int chip_index) { struct htcpld_data *htcpld; - struct device *dev = &pdev->dev; - struct htcpld_core_platform_data *pdata; struct htcpld_chip *chip; - struct htcpld_chip_platform_data *plat_chip_data; unsigned int irq, irq_end; - int ret = 0; /* Get the platform and driver data */ - pdata = dev->platform_data; htcpld = platform_get_drvdata(pdev); chip = &htcpld->chip[chip_index]; - plat_chip_data = &pdata->chip[chip_index]; /* Setup irq handlers */ irq_end = chip->irq_start + chip->nirqs; @@ -351,14 +329,10 @@ irq_set_chip_and_handler(irq, &htcpld_muxed_chip, handle_simple_irq); irq_set_chip_data(irq, chip); -#ifdef CONFIG_ARM - set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); -#else - irq_set_probe(irq); -#endif + irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); } - return ret; + return 0; } static int htcpld_register_chip_i2c( @@ -375,13 +349,13 @@ struct i2c_board_info info; /* Get the platform and driver data */ - pdata = dev->platform_data; + pdata = dev_get_platdata(dev); htcpld = platform_get_drvdata(pdev); chip = &htcpld->chip[chip_index]; plat_chip_data = &pdata->chip[chip_index]; adapter = i2c_get_adapter(pdata->i2c_adapter_id); - if (adapter == NULL) { + if (!adapter) { /* Eek, no such I2C adapter! Bail out. */ dev_warn(dev, "Chip at i2c address 0x%x: Invalid i2c adapter %d\n", plat_chip_data->addr, pdata->i2c_adapter_id); @@ -409,7 +383,7 @@ } i2c_set_clientdata(client, chip); - snprintf(client->name, I2C_NAME_SIZE, "Chip_0x%d", client->addr); + snprintf(client->name, I2C_NAME_SIZE, "Chip_0x%x", client->addr); chip->client = client; /* Reset the chip */ @@ -447,7 +421,7 @@ int ret = 0; /* Get the platform and driver data */ - pdata = dev->platform_data; + pdata = dev_get_platdata(dev); htcpld = platform_get_drvdata(pdev); chip = &htcpld->chip[chip_index]; plat_chip_data = &pdata->chip[chip_index]; @@ -486,15 +460,9 @@ ret = gpiochip_add(&(chip->chip_in)); if (ret) { - int error; - dev_warn(dev, "Unable to register input GPIOs for 0x%x: %d\n", plat_chip_data->addr, ret); - - error = gpiochip_remove(&(chip->chip_out)); - if (error) - dev_warn(dev, "Error while trying to unregister gpio chip: %d\n", error); - + gpiochip_remove(&(chip->chip_out)); return ret; } @@ -509,13 +477,13 @@ int i; /* Get the platform and driver data */ - pdata = dev->platform_data; + pdata = dev_get_platdata(dev); htcpld = platform_get_drvdata(pdev); /* Setup each chip's output GPIOs */ htcpld->nchips = pdata->num_chip; - htcpld->chip = kzalloc(sizeof(struct htcpld_chip) * htcpld->nchips, - GFP_KERNEL); + htcpld->chip = devm_kzalloc(dev, sizeof(struct htcpld_chip) * htcpld->nchips, + GFP_KERNEL); if (!htcpld->chip) { dev_warn(dev, "Unable to allocate memory for chips\n"); return -ENOMEM; @@ -574,31 +542,31 @@ if (!dev) return -ENODEV; - pdata = dev->platform_data; + pdata = dev_get_platdata(dev); if (!pdata) { dev_warn(dev, "Platform data not found for htcpld core!\n"); return -ENXIO; } - htcpld = kzalloc(sizeof(struct htcpld_data), GFP_KERNEL); + htcpld = devm_kzalloc(dev, sizeof(struct htcpld_data), GFP_KERNEL); if (!htcpld) return -ENOMEM; /* Find chained irq */ - ret = -EINVAL; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res) { int flags; htcpld->chained_irq = res->start; /* Setup the chained interrupt handler */ - flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING; + flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | + IRQF_ONESHOT; ret = request_threaded_irq(htcpld->chained_irq, NULL, htcpld_handler, flags, pdev->name, htcpld); if (ret) { dev_warn(dev, "Unable to setup chained irq handler: %d\n", ret); - goto fail; + return ret; } else device_init_wakeup(dev, 0); } @@ -609,7 +577,7 @@ /* Setup the htcpld chips */ ret = htcpld_setup_chips(pdev); if (ret) - goto fail; + return ret; /* Request the GPIO(s) for the int reset and set them up */ if (pdata->int_reset_gpio_hi) { @@ -644,10 +612,6 @@ dev_info(dev, "Initialized successfully\n"); return 0; - -fail: - kfree(htcpld); - return ret; } /* The I2C Driver -- used internally */