1c71bcdcbSAjay Gupta // SPDX-License-Identifier: GPL-2.0 2c71bcdcbSAjay Gupta /* 3c71bcdcbSAjay Gupta * Nvidia GPU I2C controller Driver 4c71bcdcbSAjay Gupta * 5c71bcdcbSAjay Gupta * Copyright (C) 2018 NVIDIA Corporation. All rights reserved. 6c71bcdcbSAjay Gupta * Author: Ajay Gupta <ajayg@nvidia.com> 7c71bcdcbSAjay Gupta */ 8c71bcdcbSAjay Gupta #include <linux/delay.h> 9c71bcdcbSAjay Gupta #include <linux/i2c.h> 10c71bcdcbSAjay Gupta #include <linux/interrupt.h> 11c71bcdcbSAjay Gupta #include <linux/module.h> 12c71bcdcbSAjay Gupta #include <linux/pci.h> 13c71bcdcbSAjay Gupta #include <linux/platform_device.h> 14c71bcdcbSAjay Gupta #include <linux/pm.h> 15c71bcdcbSAjay Gupta #include <linux/pm_runtime.h> 16c71bcdcbSAjay Gupta 17c71bcdcbSAjay Gupta #include <asm/unaligned.h> 18c71bcdcbSAjay Gupta 19c71bcdcbSAjay Gupta /* I2C definitions */ 20c71bcdcbSAjay Gupta #define I2C_MST_CNTL 0x00 21c71bcdcbSAjay Gupta #define I2C_MST_CNTL_GEN_START BIT(0) 22c71bcdcbSAjay Gupta #define I2C_MST_CNTL_GEN_STOP BIT(1) 23c71bcdcbSAjay Gupta #define I2C_MST_CNTL_CMD_READ (1 << 2) 24c71bcdcbSAjay Gupta #define I2C_MST_CNTL_CMD_WRITE (2 << 2) 25c71bcdcbSAjay Gupta #define I2C_MST_CNTL_BURST_SIZE_SHIFT 6 26c71bcdcbSAjay Gupta #define I2C_MST_CNTL_GEN_NACK BIT(28) 27c71bcdcbSAjay Gupta #define I2C_MST_CNTL_STATUS GENMASK(30, 29) 28c71bcdcbSAjay Gupta #define I2C_MST_CNTL_STATUS_OKAY (0 << 29) 29c71bcdcbSAjay Gupta #define I2C_MST_CNTL_STATUS_NO_ACK (1 << 29) 30c71bcdcbSAjay Gupta #define I2C_MST_CNTL_STATUS_TIMEOUT (2 << 29) 31c71bcdcbSAjay Gupta #define I2C_MST_CNTL_STATUS_BUS_BUSY (3 << 29) 32c71bcdcbSAjay Gupta #define I2C_MST_CNTL_CYCLE_TRIGGER BIT(31) 33c71bcdcbSAjay Gupta 34c71bcdcbSAjay Gupta #define I2C_MST_ADDR 0x04 35c71bcdcbSAjay Gupta 36c71bcdcbSAjay Gupta #define I2C_MST_I2C0_TIMING 0x08 37c71bcdcbSAjay Gupta #define I2C_MST_I2C0_TIMING_SCL_PERIOD_100KHZ 0x10e 38c71bcdcbSAjay Gupta #define I2C_MST_I2C0_TIMING_TIMEOUT_CLK_CNT 16 39c71bcdcbSAjay Gupta #define I2C_MST_I2C0_TIMING_TIMEOUT_CLK_CNT_MAX 255 40c71bcdcbSAjay Gupta #define I2C_MST_I2C0_TIMING_TIMEOUT_CHECK BIT(24) 41c71bcdcbSAjay Gupta 42c71bcdcbSAjay Gupta #define I2C_MST_DATA 0x0c 43c71bcdcbSAjay Gupta 44c71bcdcbSAjay Gupta #define I2C_MST_HYBRID_PADCTL 0x20 45c71bcdcbSAjay Gupta #define I2C_MST_HYBRID_PADCTL_MODE_I2C BIT(0) 46c71bcdcbSAjay Gupta #define I2C_MST_HYBRID_PADCTL_I2C_SCL_INPUT_RCV BIT(14) 47c71bcdcbSAjay Gupta #define I2C_MST_HYBRID_PADCTL_I2C_SDA_INPUT_RCV BIT(15) 48c71bcdcbSAjay Gupta 49c71bcdcbSAjay Gupta struct gpu_i2c_dev { 50c71bcdcbSAjay Gupta struct device *dev; 51c71bcdcbSAjay Gupta void __iomem *regs; 52c71bcdcbSAjay Gupta struct i2c_adapter adapter; 53c71bcdcbSAjay Gupta struct i2c_board_info *gpu_ccgx_ucsi; 54c71bcdcbSAjay Gupta }; 55c71bcdcbSAjay Gupta 56c71bcdcbSAjay Gupta static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd) 57c71bcdcbSAjay Gupta { 58c71bcdcbSAjay Gupta u32 val; 59c71bcdcbSAjay Gupta 60c71bcdcbSAjay Gupta /* enable I2C */ 61c71bcdcbSAjay Gupta val = readl(i2cd->regs + I2C_MST_HYBRID_PADCTL); 62c71bcdcbSAjay Gupta val |= I2C_MST_HYBRID_PADCTL_MODE_I2C | 63c71bcdcbSAjay Gupta I2C_MST_HYBRID_PADCTL_I2C_SCL_INPUT_RCV | 64c71bcdcbSAjay Gupta I2C_MST_HYBRID_PADCTL_I2C_SDA_INPUT_RCV; 65c71bcdcbSAjay Gupta writel(val, i2cd->regs + I2C_MST_HYBRID_PADCTL); 66c71bcdcbSAjay Gupta 67c71bcdcbSAjay Gupta /* enable 100KHZ mode */ 68c71bcdcbSAjay Gupta val = I2C_MST_I2C0_TIMING_SCL_PERIOD_100KHZ; 69c71bcdcbSAjay Gupta val |= (I2C_MST_I2C0_TIMING_TIMEOUT_CLK_CNT_MAX 70c71bcdcbSAjay Gupta << I2C_MST_I2C0_TIMING_TIMEOUT_CLK_CNT); 71c71bcdcbSAjay Gupta val |= I2C_MST_I2C0_TIMING_TIMEOUT_CHECK; 72c71bcdcbSAjay Gupta writel(val, i2cd->regs + I2C_MST_I2C0_TIMING); 73c71bcdcbSAjay Gupta } 74c71bcdcbSAjay Gupta 75c71bcdcbSAjay Gupta static int gpu_i2c_check_status(struct gpu_i2c_dev *i2cd) 76c71bcdcbSAjay Gupta { 77c71bcdcbSAjay Gupta unsigned long target = jiffies + msecs_to_jiffies(1000); 78c71bcdcbSAjay Gupta u32 val; 79c71bcdcbSAjay Gupta 80c71bcdcbSAjay Gupta do { 81c71bcdcbSAjay Gupta val = readl(i2cd->regs + I2C_MST_CNTL); 82c71bcdcbSAjay Gupta if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER)) 83c71bcdcbSAjay Gupta break; 84c71bcdcbSAjay Gupta if ((val & I2C_MST_CNTL_STATUS) != 85c71bcdcbSAjay Gupta I2C_MST_CNTL_STATUS_BUS_BUSY) 86c71bcdcbSAjay Gupta break; 87c71bcdcbSAjay Gupta usleep_range(500, 600); 88c71bcdcbSAjay Gupta } while (time_is_after_jiffies(target)); 89c71bcdcbSAjay Gupta 90c71bcdcbSAjay Gupta if (time_is_before_jiffies(target)) { 91c71bcdcbSAjay Gupta dev_err(i2cd->dev, "i2c timeout error %x\n", val); 9298be694bSWolfram Sang return -ETIMEDOUT; 93c71bcdcbSAjay Gupta } 94c71bcdcbSAjay Gupta 95c71bcdcbSAjay Gupta val = readl(i2cd->regs + I2C_MST_CNTL); 96c71bcdcbSAjay Gupta switch (val & I2C_MST_CNTL_STATUS) { 97c71bcdcbSAjay Gupta case I2C_MST_CNTL_STATUS_OKAY: 98c71bcdcbSAjay Gupta return 0; 99c71bcdcbSAjay Gupta case I2C_MST_CNTL_STATUS_NO_ACK: 10098be694bSWolfram Sang return -ENXIO; 101c71bcdcbSAjay Gupta case I2C_MST_CNTL_STATUS_TIMEOUT: 10298be694bSWolfram Sang return -ETIMEDOUT; 103c71bcdcbSAjay Gupta default: 104c71bcdcbSAjay Gupta return 0; 105c71bcdcbSAjay Gupta } 106c71bcdcbSAjay Gupta } 107c71bcdcbSAjay Gupta 108c71bcdcbSAjay Gupta static int gpu_i2c_read(struct gpu_i2c_dev *i2cd, u8 *data, u16 len) 109c71bcdcbSAjay Gupta { 110c71bcdcbSAjay Gupta int status; 111c71bcdcbSAjay Gupta u32 val; 112c71bcdcbSAjay Gupta 113c71bcdcbSAjay Gupta val = I2C_MST_CNTL_GEN_START | I2C_MST_CNTL_CMD_READ | 114c71bcdcbSAjay Gupta (len << I2C_MST_CNTL_BURST_SIZE_SHIFT) | 115c71bcdcbSAjay Gupta I2C_MST_CNTL_CYCLE_TRIGGER | I2C_MST_CNTL_GEN_NACK; 116c71bcdcbSAjay Gupta writel(val, i2cd->regs + I2C_MST_CNTL); 117c71bcdcbSAjay Gupta 118c71bcdcbSAjay Gupta status = gpu_i2c_check_status(i2cd); 119c71bcdcbSAjay Gupta if (status < 0) 120c71bcdcbSAjay Gupta return status; 121c71bcdcbSAjay Gupta 122c71bcdcbSAjay Gupta val = readl(i2cd->regs + I2C_MST_DATA); 123c71bcdcbSAjay Gupta switch (len) { 124c71bcdcbSAjay Gupta case 1: 125c71bcdcbSAjay Gupta data[0] = val; 126c71bcdcbSAjay Gupta break; 127c71bcdcbSAjay Gupta case 2: 128c71bcdcbSAjay Gupta put_unaligned_be16(val, data); 129c71bcdcbSAjay Gupta break; 130c71bcdcbSAjay Gupta case 3: 131c71bcdcbSAjay Gupta put_unaligned_be16(val >> 8, data); 132c71bcdcbSAjay Gupta data[2] = val; 133c71bcdcbSAjay Gupta break; 134c71bcdcbSAjay Gupta case 4: 135c71bcdcbSAjay Gupta put_unaligned_be32(val, data); 136c71bcdcbSAjay Gupta break; 137c71bcdcbSAjay Gupta default: 138c71bcdcbSAjay Gupta break; 139c71bcdcbSAjay Gupta } 140c71bcdcbSAjay Gupta return status; 141c71bcdcbSAjay Gupta } 142c71bcdcbSAjay Gupta 143c71bcdcbSAjay Gupta static int gpu_i2c_start(struct gpu_i2c_dev *i2cd) 144c71bcdcbSAjay Gupta { 145c71bcdcbSAjay Gupta writel(I2C_MST_CNTL_GEN_START, i2cd->regs + I2C_MST_CNTL); 146c71bcdcbSAjay Gupta return gpu_i2c_check_status(i2cd); 147c71bcdcbSAjay Gupta } 148c71bcdcbSAjay Gupta 149c71bcdcbSAjay Gupta static int gpu_i2c_stop(struct gpu_i2c_dev *i2cd) 150c71bcdcbSAjay Gupta { 151c71bcdcbSAjay Gupta writel(I2C_MST_CNTL_GEN_STOP, i2cd->regs + I2C_MST_CNTL); 152c71bcdcbSAjay Gupta return gpu_i2c_check_status(i2cd); 153c71bcdcbSAjay Gupta } 154c71bcdcbSAjay Gupta 155c71bcdcbSAjay Gupta static int gpu_i2c_write(struct gpu_i2c_dev *i2cd, u8 data) 156c71bcdcbSAjay Gupta { 157c71bcdcbSAjay Gupta u32 val; 158c71bcdcbSAjay Gupta 159c71bcdcbSAjay Gupta writel(data, i2cd->regs + I2C_MST_DATA); 160c71bcdcbSAjay Gupta 161c71bcdcbSAjay Gupta val = I2C_MST_CNTL_CMD_WRITE | (1 << I2C_MST_CNTL_BURST_SIZE_SHIFT); 162c71bcdcbSAjay Gupta writel(val, i2cd->regs + I2C_MST_CNTL); 163c71bcdcbSAjay Gupta 164c71bcdcbSAjay Gupta return gpu_i2c_check_status(i2cd); 165c71bcdcbSAjay Gupta } 166c71bcdcbSAjay Gupta 167c71bcdcbSAjay Gupta static int gpu_i2c_master_xfer(struct i2c_adapter *adap, 168c71bcdcbSAjay Gupta struct i2c_msg *msgs, int num) 169c71bcdcbSAjay Gupta { 170c71bcdcbSAjay Gupta struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap); 171c71bcdcbSAjay Gupta int status, status2; 172c71bcdcbSAjay Gupta int i, j; 173c71bcdcbSAjay Gupta 174c71bcdcbSAjay Gupta /* 175c71bcdcbSAjay Gupta * The controller supports maximum 4 byte read due to known 176c71bcdcbSAjay Gupta * limitation of sending STOP after every read. 177c71bcdcbSAjay Gupta */ 178c71bcdcbSAjay Gupta for (i = 0; i < num; i++) { 179c71bcdcbSAjay Gupta if (msgs[i].flags & I2C_M_RD) { 180c71bcdcbSAjay Gupta /* program client address before starting read */ 181c71bcdcbSAjay Gupta writel(msgs[i].addr, i2cd->regs + I2C_MST_ADDR); 182c71bcdcbSAjay Gupta /* gpu_i2c_read has implicit start */ 183c71bcdcbSAjay Gupta status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len); 184c71bcdcbSAjay Gupta if (status < 0) 185c71bcdcbSAjay Gupta goto stop; 186c71bcdcbSAjay Gupta } else { 187c71bcdcbSAjay Gupta u8 addr = i2c_8bit_addr_from_msg(msgs + i); 188c71bcdcbSAjay Gupta 189c71bcdcbSAjay Gupta status = gpu_i2c_start(i2cd); 190c71bcdcbSAjay Gupta if (status < 0) { 191c71bcdcbSAjay Gupta if (i == 0) 192c71bcdcbSAjay Gupta return status; 193c71bcdcbSAjay Gupta goto stop; 194c71bcdcbSAjay Gupta } 195c71bcdcbSAjay Gupta 196c71bcdcbSAjay Gupta status = gpu_i2c_write(i2cd, addr); 197c71bcdcbSAjay Gupta if (status < 0) 198c71bcdcbSAjay Gupta goto stop; 199c71bcdcbSAjay Gupta 200c71bcdcbSAjay Gupta for (j = 0; j < msgs[i].len; j++) { 201c71bcdcbSAjay Gupta status = gpu_i2c_write(i2cd, msgs[i].buf[j]); 202c71bcdcbSAjay Gupta if (status < 0) 203c71bcdcbSAjay Gupta goto stop; 204c71bcdcbSAjay Gupta } 205c71bcdcbSAjay Gupta } 206c71bcdcbSAjay Gupta } 207c71bcdcbSAjay Gupta status = gpu_i2c_stop(i2cd); 208c71bcdcbSAjay Gupta if (status < 0) 209c71bcdcbSAjay Gupta return status; 210c71bcdcbSAjay Gupta 211c71bcdcbSAjay Gupta return i; 212c71bcdcbSAjay Gupta stop: 213c71bcdcbSAjay Gupta status2 = gpu_i2c_stop(i2cd); 214c71bcdcbSAjay Gupta if (status2 < 0) 215c71bcdcbSAjay Gupta dev_err(i2cd->dev, "i2c stop failed %d\n", status2); 216c71bcdcbSAjay Gupta return status; 217c71bcdcbSAjay Gupta } 218c71bcdcbSAjay Gupta 219c71bcdcbSAjay Gupta static const struct i2c_adapter_quirks gpu_i2c_quirks = { 220c71bcdcbSAjay Gupta .max_read_len = 4, 221c71bcdcbSAjay Gupta .flags = I2C_AQ_COMB_WRITE_THEN_READ, 222c71bcdcbSAjay Gupta }; 223c71bcdcbSAjay Gupta 224c71bcdcbSAjay Gupta static u32 gpu_i2c_functionality(struct i2c_adapter *adap) 225c71bcdcbSAjay Gupta { 226c71bcdcbSAjay Gupta return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 227c71bcdcbSAjay Gupta } 228c71bcdcbSAjay Gupta 229c71bcdcbSAjay Gupta static const struct i2c_algorithm gpu_i2c_algorithm = { 230c71bcdcbSAjay Gupta .master_xfer = gpu_i2c_master_xfer, 231c71bcdcbSAjay Gupta .functionality = gpu_i2c_functionality, 232c71bcdcbSAjay Gupta }; 233c71bcdcbSAjay Gupta 234c71bcdcbSAjay Gupta /* 235c71bcdcbSAjay Gupta * This driver is for Nvidia GPU cards with USB Type-C interface. 236c71bcdcbSAjay Gupta * We want to identify the cards using vendor ID and class code only 237c71bcdcbSAjay Gupta * to avoid dependency of adding product id for any new card which 238c71bcdcbSAjay Gupta * requires this driver. 239c71bcdcbSAjay Gupta * Currently there is no class code defined for UCSI device over PCI 240c71bcdcbSAjay Gupta * so using UNKNOWN class for now and it will be updated when UCSI 241c71bcdcbSAjay Gupta * over PCI gets a class code. 242c71bcdcbSAjay Gupta * There is no other NVIDIA cards with UNKNOWN class code. Even if the 243c71bcdcbSAjay Gupta * driver gets loaded for an undesired card then eventually i2c_read() 244c71bcdcbSAjay Gupta * (initiated from UCSI i2c_client) will timeout or UCSI commands will 245c71bcdcbSAjay Gupta * timeout. 246c71bcdcbSAjay Gupta */ 247c71bcdcbSAjay Gupta #define PCI_CLASS_SERIAL_UNKNOWN 0x0c80 248c71bcdcbSAjay Gupta static const struct pci_device_id gpu_i2c_ids[] = { 249c71bcdcbSAjay Gupta { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 250c71bcdcbSAjay Gupta PCI_CLASS_SERIAL_UNKNOWN << 8, 0xffffff00}, 251c71bcdcbSAjay Gupta { } 252c71bcdcbSAjay Gupta }; 253c71bcdcbSAjay Gupta MODULE_DEVICE_TABLE(pci, gpu_i2c_ids); 254c71bcdcbSAjay Gupta 255c71bcdcbSAjay Gupta static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq) 256c71bcdcbSAjay Gupta { 257c71bcdcbSAjay Gupta struct i2c_client *ccgx_client; 258c71bcdcbSAjay Gupta 259c71bcdcbSAjay Gupta i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev, 260c71bcdcbSAjay Gupta sizeof(*i2cd->gpu_ccgx_ucsi), 261c71bcdcbSAjay Gupta GFP_KERNEL); 262c71bcdcbSAjay Gupta if (!i2cd->gpu_ccgx_ucsi) 263c71bcdcbSAjay Gupta return -ENOMEM; 264c71bcdcbSAjay Gupta 265c71bcdcbSAjay Gupta strlcpy(i2cd->gpu_ccgx_ucsi->type, "ccgx-ucsi", 266c71bcdcbSAjay Gupta sizeof(i2cd->gpu_ccgx_ucsi->type)); 267c71bcdcbSAjay Gupta i2cd->gpu_ccgx_ucsi->addr = 0x8; 268c71bcdcbSAjay Gupta i2cd->gpu_ccgx_ucsi->irq = irq; 269c71bcdcbSAjay Gupta ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi); 270c71bcdcbSAjay Gupta if (!ccgx_client) 271c71bcdcbSAjay Gupta return -ENODEV; 272c71bcdcbSAjay Gupta 273c71bcdcbSAjay Gupta return 0; 274c71bcdcbSAjay Gupta } 275c71bcdcbSAjay Gupta 276c71bcdcbSAjay Gupta static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id) 277c71bcdcbSAjay Gupta { 278c71bcdcbSAjay Gupta struct gpu_i2c_dev *i2cd; 279c71bcdcbSAjay Gupta int status; 280c71bcdcbSAjay Gupta 281c71bcdcbSAjay Gupta i2cd = devm_kzalloc(&pdev->dev, sizeof(*i2cd), GFP_KERNEL); 282c71bcdcbSAjay Gupta if (!i2cd) 283c71bcdcbSAjay Gupta return -ENOMEM; 284c71bcdcbSAjay Gupta 285c71bcdcbSAjay Gupta i2cd->dev = &pdev->dev; 286c71bcdcbSAjay Gupta dev_set_drvdata(&pdev->dev, i2cd); 287c71bcdcbSAjay Gupta 288c71bcdcbSAjay Gupta status = pcim_enable_device(pdev); 289c71bcdcbSAjay Gupta if (status < 0) { 290c71bcdcbSAjay Gupta dev_err(&pdev->dev, "pcim_enable_device failed %d\n", status); 291c71bcdcbSAjay Gupta return status; 292c71bcdcbSAjay Gupta } 293c71bcdcbSAjay Gupta 294c71bcdcbSAjay Gupta pci_set_master(pdev); 295c71bcdcbSAjay Gupta 296c71bcdcbSAjay Gupta i2cd->regs = pcim_iomap(pdev, 0, 0); 297c71bcdcbSAjay Gupta if (!i2cd->regs) { 298c71bcdcbSAjay Gupta dev_err(&pdev->dev, "pcim_iomap failed\n"); 299c71bcdcbSAjay Gupta return -ENOMEM; 300c71bcdcbSAjay Gupta } 301c71bcdcbSAjay Gupta 302c71bcdcbSAjay Gupta status = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); 303c71bcdcbSAjay Gupta if (status < 0) { 304c71bcdcbSAjay Gupta dev_err(&pdev->dev, "pci_alloc_irq_vectors err %d\n", status); 305c71bcdcbSAjay Gupta return status; 306c71bcdcbSAjay Gupta } 307c71bcdcbSAjay Gupta 308c71bcdcbSAjay Gupta gpu_enable_i2c_bus(i2cd); 309c71bcdcbSAjay Gupta 310c71bcdcbSAjay Gupta i2c_set_adapdata(&i2cd->adapter, i2cd); 311c71bcdcbSAjay Gupta i2cd->adapter.owner = THIS_MODULE; 312c71bcdcbSAjay Gupta strlcpy(i2cd->adapter.name, "NVIDIA GPU I2C adapter", 313c71bcdcbSAjay Gupta sizeof(i2cd->adapter.name)); 314c71bcdcbSAjay Gupta i2cd->adapter.algo = &gpu_i2c_algorithm; 315c71bcdcbSAjay Gupta i2cd->adapter.quirks = &gpu_i2c_quirks; 316c71bcdcbSAjay Gupta i2cd->adapter.dev.parent = &pdev->dev; 317c71bcdcbSAjay Gupta status = i2c_add_adapter(&i2cd->adapter); 318c71bcdcbSAjay Gupta if (status < 0) 319c71bcdcbSAjay Gupta goto free_irq_vectors; 320c71bcdcbSAjay Gupta 321c71bcdcbSAjay Gupta status = gpu_populate_client(i2cd, pdev->irq); 322c71bcdcbSAjay Gupta if (status < 0) { 323c71bcdcbSAjay Gupta dev_err(&pdev->dev, "gpu_populate_client failed %d\n", status); 324c71bcdcbSAjay Gupta goto del_adapter; 325c71bcdcbSAjay Gupta } 326c71bcdcbSAjay Gupta 327c71bcdcbSAjay Gupta return 0; 328c71bcdcbSAjay Gupta 329c71bcdcbSAjay Gupta del_adapter: 330c71bcdcbSAjay Gupta i2c_del_adapter(&i2cd->adapter); 331c71bcdcbSAjay Gupta free_irq_vectors: 332c71bcdcbSAjay Gupta pci_free_irq_vectors(pdev); 333c71bcdcbSAjay Gupta return status; 334c71bcdcbSAjay Gupta } 335c71bcdcbSAjay Gupta 336c71bcdcbSAjay Gupta static void gpu_i2c_remove(struct pci_dev *pdev) 337c71bcdcbSAjay Gupta { 338c71bcdcbSAjay Gupta struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev); 339c71bcdcbSAjay Gupta 340c71bcdcbSAjay Gupta i2c_del_adapter(&i2cd->adapter); 341c71bcdcbSAjay Gupta pci_free_irq_vectors(pdev); 342c71bcdcbSAjay Gupta } 343c71bcdcbSAjay Gupta 344c71bcdcbSAjay Gupta static int gpu_i2c_resume(struct device *dev) 345c71bcdcbSAjay Gupta { 346c71bcdcbSAjay Gupta struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); 347c71bcdcbSAjay Gupta 348c71bcdcbSAjay Gupta gpu_enable_i2c_bus(i2cd); 349c71bcdcbSAjay Gupta return 0; 350c71bcdcbSAjay Gupta } 351c71bcdcbSAjay Gupta 352caccdcc5SWolfram Sang static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, NULL, gpu_i2c_resume, NULL); 353c71bcdcbSAjay Gupta 354c71bcdcbSAjay Gupta static struct pci_driver gpu_i2c_driver = { 355c71bcdcbSAjay Gupta .name = "nvidia-gpu", 356c71bcdcbSAjay Gupta .id_table = gpu_i2c_ids, 357c71bcdcbSAjay Gupta .probe = gpu_i2c_probe, 358c71bcdcbSAjay Gupta .remove = gpu_i2c_remove, 359c71bcdcbSAjay Gupta .driver = { 360c71bcdcbSAjay Gupta .pm = &gpu_i2c_driver_pm, 361c71bcdcbSAjay Gupta }, 362c71bcdcbSAjay Gupta }; 363c71bcdcbSAjay Gupta 364c71bcdcbSAjay Gupta module_pci_driver(gpu_i2c_driver); 365c71bcdcbSAjay Gupta 366c71bcdcbSAjay Gupta MODULE_AUTHOR("Ajay Gupta <ajayg@nvidia.com>"); 367c71bcdcbSAjay Gupta MODULE_DESCRIPTION("Nvidia GPU I2C controller Driver"); 368c71bcdcbSAjay Gupta MODULE_LICENSE("GPL v2"); 369