tpm: two-phase chip management functions
[cascardo/linux.git] / drivers / char / tpm / tpm_i2c_atmel.c
index c3cd7fe..643a940 100644 (file)
@@ -135,50 +135,12 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
        return ATMEL_STS_OK;
 }
 
-static const struct file_operations i2c_atmel_ops = {
-       .owner = THIS_MODULE,
-       .llseek = no_llseek,
-       .open = tpm_open,
-       .read = tpm_read,
-       .write = tpm_write,
-       .release = tpm_release,
-};
-
-static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
-static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
-static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
-static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
-static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
-static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated, NULL);
-static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
-static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
-static DEVICE_ATTR(durations, S_IRUGO, tpm_show_durations, NULL);
-static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL);
-
-static struct attribute *i2c_atmel_attrs[] = {
-       &dev_attr_pubek.attr,
-       &dev_attr_pcrs.attr,
-       &dev_attr_enabled.attr,
-       &dev_attr_active.attr,
-       &dev_attr_owned.attr,
-       &dev_attr_temp_deactivated.attr,
-       &dev_attr_caps.attr,
-       &dev_attr_cancel.attr,
-       &dev_attr_durations.attr,
-       &dev_attr_timeouts.attr,
-       NULL,
-};
-
-static struct attribute_group i2c_atmel_attr_grp = {
-       .attrs = i2c_atmel_attrs
-};
-
 static bool i2c_atmel_req_canceled(struct tpm_chip *chip, u8 status)
 {
-       return 0;
+       return false;
 }
 
-static const struct tpm_vendor_specific i2c_atmel = {
+static const struct tpm_class_ops i2c_atmel = {
        .status = i2c_atmel_read_status,
        .recv = i2c_atmel_recv,
        .send = i2c_atmel_send,
@@ -186,28 +148,25 @@ static const struct tpm_vendor_specific i2c_atmel = {
        .req_complete_mask = ATMEL_STS_OK,
        .req_complete_val = ATMEL_STS_OK,
        .req_canceled = i2c_atmel_req_canceled,
-       .attr_group = &i2c_atmel_attr_grp,
-       .miscdev.fops = &i2c_atmel_ops,
 };
 
 static int i2c_atmel_probe(struct i2c_client *client,
                           const struct i2c_device_id *id)
 {
-       int rc;
        struct tpm_chip *chip;
        struct device *dev = &client->dev;
 
        if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
                return -ENODEV;
 
-       chip = tpm_register_hardware(dev, &i2c_atmel);
-       if (!chip) {
-               dev_err(dev, "%s() error in tpm_register_hardware\n", __func__);
-               return -ENODEV;
-       }
+       chip = tpmm_chip_alloc(dev, &i2c_atmel);
+       if (IS_ERR(chip))
+               return PTR_ERR(chip);
 
        chip->vendor.priv = devm_kzalloc(dev, sizeof(struct priv_data),
                                         GFP_KERNEL);
+       if (!chip->vendor.priv)
+               return -ENOMEM;
 
        /* Default timeouts */
        chip->vendor.timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
@@ -219,33 +178,20 @@ static int i2c_atmel_probe(struct i2c_client *client,
        /* There is no known way to probe for this device, and all version
         * information seems to be read via TPM commands. Thus we rely on the
         * TPM startup process in the common code to detect the device. */
-       if (tpm_get_timeouts(chip)) {
-               rc = -ENODEV;
-               goto out_err;
-       }
-
-       if (tpm_do_selftest(chip)) {
-               rc = -ENODEV;
-               goto out_err;
-       }
+       if (tpm_get_timeouts(chip))
+               return -ENODEV;
 
-       return 0;
+       if (tpm_do_selftest(chip))
+               return -ENODEV;
 
-out_err:
-       tpm_dev_vendor_release(chip);
-       tpm_remove_hardware(chip->dev);
-       return rc;
+       return tpm_chip_register(chip);
 }
 
 static int i2c_atmel_remove(struct i2c_client *client)
 {
        struct device *dev = &(client->dev);
        struct tpm_chip *chip = dev_get_drvdata(dev);
-
-       if (chip)
-               tpm_dev_vendor_release(chip);
-       tpm_remove_hardware(dev);
-       kfree(chip);
+       tpm_chip_unregister(chip);
        return 0;
 }