Lines Matching refs:adap
58 struct cht_wc_i2c_adap *adap = data; in cht_wc_i2c_adap_thread_handler() local
61 mutex_lock(&adap->adap_lock); in cht_wc_i2c_adap_thread_handler()
64 ret = regmap_read(adap->regmap, CHT_WC_EXTCHGRIRQ, ®); in cht_wc_i2c_adap_thread_handler()
66 dev_err(&adap->adapter.dev, "Error reading extchgrirq reg\n"); in cht_wc_i2c_adap_thread_handler()
67 mutex_unlock(&adap->adap_lock); in cht_wc_i2c_adap_thread_handler()
71 reg &= ~adap->irq_mask; in cht_wc_i2c_adap_thread_handler()
74 ret = regmap_read(adap->regmap, CHT_WC_I2C_RDDATA, &adap->read_data); in cht_wc_i2c_adap_thread_handler()
76 adap->io_error = true; in cht_wc_i2c_adap_thread_handler()
82 ret = regmap_write(adap->regmap, CHT_WC_EXTCHGRIRQ, reg); in cht_wc_i2c_adap_thread_handler()
84 dev_err(&adap->adapter.dev, "Error writing extchgrirq reg\n"); in cht_wc_i2c_adap_thread_handler()
87 adap->io_error |= !!(reg & CHT_WC_EXTCHGRIRQ_NACK_IRQ); in cht_wc_i2c_adap_thread_handler()
88 adap->done = true; in cht_wc_i2c_adap_thread_handler()
91 mutex_unlock(&adap->adap_lock); in cht_wc_i2c_adap_thread_handler()
94 wake_up(&adap->wait); in cht_wc_i2c_adap_thread_handler()
108 generic_handle_irq(adap->client_irq); in cht_wc_i2c_adap_thread_handler()
115 static u32 cht_wc_i2c_adap_master_func(struct i2c_adapter *adap) in cht_wc_i2c_adap_master_func() argument
126 struct cht_wc_i2c_adap *adap = i2c_get_adapdata(_adap); in cht_wc_i2c_adap_smbus_xfer() local
129 mutex_lock(&adap->adap_lock); in cht_wc_i2c_adap_smbus_xfer()
130 adap->io_error = false; in cht_wc_i2c_adap_smbus_xfer()
131 adap->done = false; in cht_wc_i2c_adap_smbus_xfer()
132 mutex_unlock(&adap->adap_lock); in cht_wc_i2c_adap_smbus_xfer()
134 ret = regmap_write(adap->regmap, CHT_WC_I2C_CLIENT_ADDR, addr); in cht_wc_i2c_adap_smbus_xfer()
139 ret = regmap_write(adap->regmap, CHT_WC_I2C_WRDATA, data->byte); in cht_wc_i2c_adap_smbus_xfer()
144 ret = regmap_write(adap->regmap, CHT_WC_I2C_REG_OFFSET, command); in cht_wc_i2c_adap_smbus_xfer()
148 ret = regmap_write(adap->regmap, CHT_WC_I2C_CTRL, in cht_wc_i2c_adap_smbus_xfer()
154 ret = wait_event_timeout(adap->wait, adap->done, msecs_to_jiffies(30)); in cht_wc_i2c_adap_smbus_xfer()
160 cht_wc_i2c_adap_thread_handler(0, adap); in cht_wc_i2c_adap_smbus_xfer()
161 if (!adap->done) in cht_wc_i2c_adap_smbus_xfer()
166 mutex_lock(&adap->adap_lock); in cht_wc_i2c_adap_smbus_xfer()
167 if (adap->io_error) in cht_wc_i2c_adap_smbus_xfer()
170 data->byte = adap->read_data; in cht_wc_i2c_adap_smbus_xfer()
171 mutex_unlock(&adap->adap_lock); in cht_wc_i2c_adap_smbus_xfer()
229 struct cht_wc_i2c_adap *adap = irq_data_get_irq_chip_data(data); in cht_wc_i2c_irq_lock() local
231 mutex_lock(&adap->irqchip_lock); in cht_wc_i2c_irq_lock()
236 struct cht_wc_i2c_adap *adap = irq_data_get_irq_chip_data(data); in cht_wc_i2c_irq_sync_unlock() local
239 if (adap->irq_mask != adap->old_irq_mask) { in cht_wc_i2c_irq_sync_unlock()
240 ret = regmap_write(adap->regmap, CHT_WC_EXTCHGRIRQ_MSK, in cht_wc_i2c_irq_sync_unlock()
241 adap->irq_mask); in cht_wc_i2c_irq_sync_unlock()
243 adap->old_irq_mask = adap->irq_mask; in cht_wc_i2c_irq_sync_unlock()
245 dev_err(&adap->adapter.dev, "Error writing EXTCHGRIRQ_MSK\n"); in cht_wc_i2c_irq_sync_unlock()
248 mutex_unlock(&adap->irqchip_lock); in cht_wc_i2c_irq_sync_unlock()
253 struct cht_wc_i2c_adap *adap = irq_data_get_irq_chip_data(data); in cht_wc_i2c_irq_enable() local
255 adap->irq_mask &= ~CHT_WC_EXTCHGRIRQ_CLIENT_IRQ; in cht_wc_i2c_irq_enable()
260 struct cht_wc_i2c_adap *adap = irq_data_get_irq_chip_data(data); in cht_wc_i2c_irq_disable() local
262 adap->irq_mask |= CHT_WC_EXTCHGRIRQ_CLIENT_IRQ; in cht_wc_i2c_irq_disable()
310 struct cht_wc_i2c_adap *adap; in cht_wc_i2c_adap_i2c_probe() local
324 adap = devm_kzalloc(&pdev->dev, sizeof(*adap), GFP_KERNEL); in cht_wc_i2c_adap_i2c_probe()
325 if (!adap) in cht_wc_i2c_adap_i2c_probe()
328 init_waitqueue_head(&adap->wait); in cht_wc_i2c_adap_i2c_probe()
329 mutex_init(&adap->adap_lock); in cht_wc_i2c_adap_i2c_probe()
330 mutex_init(&adap->irqchip_lock); in cht_wc_i2c_adap_i2c_probe()
331 adap->irqchip = cht_wc_i2c_irq_chip; in cht_wc_i2c_adap_i2c_probe()
332 adap->regmap = pmic->regmap; in cht_wc_i2c_adap_i2c_probe()
333 adap->adapter.owner = THIS_MODULE; in cht_wc_i2c_adap_i2c_probe()
334 adap->adapter.class = I2C_CLASS_HWMON; in cht_wc_i2c_adap_i2c_probe()
335 adap->adapter.algo = &cht_wc_i2c_adap_algo; in cht_wc_i2c_adap_i2c_probe()
336 adap->adapter.lock_ops = &cht_wc_i2c_adap_lock_ops; in cht_wc_i2c_adap_i2c_probe()
337 strlcpy(adap->adapter.name, "PMIC I2C Adapter", in cht_wc_i2c_adap_i2c_probe()
338 sizeof(adap->adapter.name)); in cht_wc_i2c_adap_i2c_probe()
339 adap->adapter.dev.parent = &pdev->dev; in cht_wc_i2c_adap_i2c_probe()
342 adap->old_irq_mask = adap->irq_mask = ~CHT_WC_EXTCHGRIRQ_ADAP_IRQMASK; in cht_wc_i2c_adap_i2c_probe()
344 ret = regmap_read(adap->regmap, CHT_WC_I2C_RDDATA, ®); in cht_wc_i2c_adap_i2c_probe()
348 ret = regmap_write(adap->regmap, CHT_WC_EXTCHGRIRQ, ~adap->irq_mask); in cht_wc_i2c_adap_i2c_probe()
352 ret = regmap_write(adap->regmap, CHT_WC_EXTCHGRIRQ_MSK, adap->irq_mask); in cht_wc_i2c_adap_i2c_probe()
357 adap->irq_domain = irq_domain_add_linear(NULL, 1, &irq_domain_simple_ops, NULL); in cht_wc_i2c_adap_i2c_probe()
358 if (!adap->irq_domain) in cht_wc_i2c_adap_i2c_probe()
361 adap->client_irq = irq_create_mapping(adap->irq_domain, 0); in cht_wc_i2c_adap_i2c_probe()
362 if (!adap->client_irq) { in cht_wc_i2c_adap_i2c_probe()
367 irq_set_chip_data(adap->client_irq, adap); in cht_wc_i2c_adap_i2c_probe()
368 irq_set_chip_and_handler(adap->client_irq, &adap->irqchip, in cht_wc_i2c_adap_i2c_probe()
373 IRQF_ONESHOT, "PMIC I2C Adapter", adap); in cht_wc_i2c_adap_i2c_probe()
377 i2c_set_adapdata(&adap->adapter, adap); in cht_wc_i2c_adap_i2c_probe()
378 ret = i2c_add_adapter(&adap->adapter); in cht_wc_i2c_adap_i2c_probe()
391 board_info.irq = adap->client_irq; in cht_wc_i2c_adap_i2c_probe()
392 adap->client = i2c_new_client_device(&adap->adapter, &board_info); in cht_wc_i2c_adap_i2c_probe()
393 if (IS_ERR(adap->client)) { in cht_wc_i2c_adap_i2c_probe()
394 ret = PTR_ERR(adap->client); in cht_wc_i2c_adap_i2c_probe()
399 platform_set_drvdata(pdev, adap); in cht_wc_i2c_adap_i2c_probe()
403 i2c_del_adapter(&adap->adapter); in cht_wc_i2c_adap_i2c_probe()
405 irq_domain_remove(adap->irq_domain); in cht_wc_i2c_adap_i2c_probe()
411 struct cht_wc_i2c_adap *adap = platform_get_drvdata(pdev); in cht_wc_i2c_adap_i2c_remove() local
413 i2c_unregister_device(adap->client); in cht_wc_i2c_adap_i2c_remove()
414 i2c_del_adapter(&adap->adapter); in cht_wc_i2c_adap_i2c_remove()
415 irq_domain_remove(adap->irq_domain); in cht_wc_i2c_adap_i2c_remove()