Lines Matching refs:i2cd

58 static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd)  in gpu_enable_i2c_bus()  argument
63 val = readl(i2cd->regs + I2C_MST_HYBRID_PADCTL); in gpu_enable_i2c_bus()
67 writel(val, i2cd->regs + I2C_MST_HYBRID_PADCTL); in gpu_enable_i2c_bus()
74 writel(val, i2cd->regs + I2C_MST_I2C0_TIMING); in gpu_enable_i2c_bus()
77 static int gpu_i2c_check_status(struct gpu_i2c_dev *i2cd) in gpu_i2c_check_status() argument
82 ret = readl_poll_timeout(i2cd->regs + I2C_MST_CNTL, val, in gpu_i2c_check_status()
88 dev_err(i2cd->dev, "i2c timeout error %x\n", val); in gpu_i2c_check_status()
92 val = readl(i2cd->regs + I2C_MST_CNTL); in gpu_i2c_check_status()
105 static int gpu_i2c_read(struct gpu_i2c_dev *i2cd, u8 *data, u16 len) in gpu_i2c_read() argument
113 writel(val, i2cd->regs + I2C_MST_CNTL); in gpu_i2c_read()
115 status = gpu_i2c_check_status(i2cd); in gpu_i2c_read()
119 val = readl(i2cd->regs + I2C_MST_DATA); in gpu_i2c_read()
139 static int gpu_i2c_start(struct gpu_i2c_dev *i2cd) in gpu_i2c_start() argument
141 writel(I2C_MST_CNTL_GEN_START, i2cd->regs + I2C_MST_CNTL); in gpu_i2c_start()
142 return gpu_i2c_check_status(i2cd); in gpu_i2c_start()
145 static int gpu_i2c_stop(struct gpu_i2c_dev *i2cd) in gpu_i2c_stop() argument
147 writel(I2C_MST_CNTL_GEN_STOP, i2cd->regs + I2C_MST_CNTL); in gpu_i2c_stop()
148 return gpu_i2c_check_status(i2cd); in gpu_i2c_stop()
151 static int gpu_i2c_write(struct gpu_i2c_dev *i2cd, u8 data) in gpu_i2c_write() argument
155 writel(data, i2cd->regs + I2C_MST_DATA); in gpu_i2c_write()
158 writel(val, i2cd->regs + I2C_MST_CNTL); in gpu_i2c_write()
160 return gpu_i2c_check_status(i2cd); in gpu_i2c_write()
166 struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap); in gpu_i2c_master_xfer() local
175 pm_runtime_get_sync(i2cd->dev); in gpu_i2c_master_xfer()
179 writel(msgs[i].addr, i2cd->regs + I2C_MST_ADDR); in gpu_i2c_master_xfer()
181 status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len); in gpu_i2c_master_xfer()
187 status = gpu_i2c_start(i2cd); in gpu_i2c_master_xfer()
194 status = gpu_i2c_write(i2cd, addr); in gpu_i2c_master_xfer()
199 status = gpu_i2c_write(i2cd, msgs[i].buf[j]); in gpu_i2c_master_xfer()
206 status = gpu_i2c_stop(i2cd); in gpu_i2c_master_xfer()
213 status2 = gpu_i2c_stop(i2cd); in gpu_i2c_master_xfer()
215 dev_err(i2cd->dev, "i2c stop failed %d\n", status2); in gpu_i2c_master_xfer()
217 pm_runtime_mark_last_busy(i2cd->dev); in gpu_i2c_master_xfer()
218 pm_runtime_put_autosuspend(i2cd->dev); in gpu_i2c_master_xfer()
265 static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq) in gpu_populate_client() argument
267 i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev, in gpu_populate_client()
268 sizeof(*i2cd->gpu_ccgx_ucsi), in gpu_populate_client()
270 if (!i2cd->gpu_ccgx_ucsi) in gpu_populate_client()
273 strlcpy(i2cd->gpu_ccgx_ucsi->type, "ccgx-ucsi", in gpu_populate_client()
274 sizeof(i2cd->gpu_ccgx_ucsi->type)); in gpu_populate_client()
275 i2cd->gpu_ccgx_ucsi->addr = 0x8; in gpu_populate_client()
276 i2cd->gpu_ccgx_ucsi->irq = irq; in gpu_populate_client()
277 i2cd->gpu_ccgx_ucsi->properties = ccgx_props; in gpu_populate_client()
278 i2cd->ccgx_client = i2c_new_client_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi); in gpu_populate_client()
279 return PTR_ERR_OR_ZERO(i2cd->ccgx_client); in gpu_populate_client()
284 struct gpu_i2c_dev *i2cd; in gpu_i2c_probe() local
287 i2cd = devm_kzalloc(&pdev->dev, sizeof(*i2cd), GFP_KERNEL); in gpu_i2c_probe()
288 if (!i2cd) in gpu_i2c_probe()
291 i2cd->dev = &pdev->dev; in gpu_i2c_probe()
292 dev_set_drvdata(&pdev->dev, i2cd); in gpu_i2c_probe()
302 i2cd->regs = pcim_iomap(pdev, 0, 0); in gpu_i2c_probe()
303 if (!i2cd->regs) { in gpu_i2c_probe()
314 gpu_enable_i2c_bus(i2cd); in gpu_i2c_probe()
316 i2c_set_adapdata(&i2cd->adapter, i2cd); in gpu_i2c_probe()
317 i2cd->adapter.owner = THIS_MODULE; in gpu_i2c_probe()
318 strlcpy(i2cd->adapter.name, "NVIDIA GPU I2C adapter", in gpu_i2c_probe()
319 sizeof(i2cd->adapter.name)); in gpu_i2c_probe()
320 i2cd->adapter.algo = &gpu_i2c_algorithm; in gpu_i2c_probe()
321 i2cd->adapter.quirks = &gpu_i2c_quirks; in gpu_i2c_probe()
322 i2cd->adapter.dev.parent = &pdev->dev; in gpu_i2c_probe()
323 status = i2c_add_adapter(&i2cd->adapter); in gpu_i2c_probe()
327 status = gpu_populate_client(i2cd, pdev->irq); in gpu_i2c_probe()
341 i2c_del_adapter(&i2cd->adapter); in gpu_i2c_probe()
349 struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev); in gpu_i2c_remove() local
351 pm_runtime_get_noresume(i2cd->dev); in gpu_i2c_remove()
352 i2c_del_adapter(&i2cd->adapter); in gpu_i2c_remove()
368 struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); in gpu_i2c_resume() local
370 gpu_enable_i2c_bus(i2cd); in gpu_i2c_resume()
377 pm_request_resume(&i2cd->ccgx_client->dev); in gpu_i2c_resume()