Lines Matching +full:i2c +full:- +full:retry +full:- +full:count
1 // SPDX-License-Identifier: GPL-2.0-only
8 #include <linux/i2c.h>
37 * BU21023GUL/BU21023MUV/BU21024FV-M registers map
270 * rohm_i2c_burst_read - execute combined I2C message for ROHM BU21023/24
285 struct i2c_adapter *adap = client->adapter; in rohm_i2c_burst_read()
289 msg[0].addr = client->addr; in rohm_i2c_burst_read()
294 msg[1].addr = client->addr; in rohm_i2c_burst_read()
303 ret = -EIO; in rohm_i2c_burst_read()
315 struct i2c_client *client = ts->client; in rohm_ts_manual_calibration()
316 struct device *dev = &client->dev; in rohm_ts_manual_calibration()
317 u8 buf[33]; /* for PRM1_X_H(0x08)-TOUCH(0x28) */ in rohm_ts_manual_calibration()
319 int retry; in rohm_ts_manual_calibration() local
358 for (retry = 0; retry < CALIBRATION_RETRY_MAX; retry++) { in rohm_ts_manual_calibration()
362 #define READ_CALIB_BUF(reg) buf[((reg) - PRM1_X_H)] in rohm_ts_manual_calibration()
374 READ_CALIB_BUF(PRM1_X_L)) - AXIS_OFFSET; in rohm_ts_manual_calibration()
376 READ_CALIB_BUF(PRM1_Y_L)) - AXIS_OFFSET; in rohm_ts_manual_calibration()
393 calib_x -= AXIS_ADJUST; in rohm_ts_manual_calibration()
399 calib_y -= AXIS_ADJUST; in rohm_ts_manual_calibration()
504 error = -EBUSY; in rohm_ts_manual_calibration()
523 struct i2c_client *client = ts->client; in rohm_ts_soft_irq()
524 struct input_dev *input_dev = ts->input; in rohm_ts_soft_irq()
525 struct device *dev = &client->dev; in rohm_ts_soft_irq()
527 u8 buf[10]; /* for POS_X1_H(0x20)-TOUCH_GESTURE(0x29) */ in rohm_ts_soft_irq()
533 int finger_count = -1; in rohm_ts_soft_irq()
534 int prev_finger_count = ts->finger_count; in rohm_ts_soft_irq()
535 int count; in rohm_ts_soft_irq() local
548 #define READ_POS_BUF(reg) buf[((reg) - POS_X1_H)] in rohm_ts_soft_irq()
570 if (++ts->contact_count[0] >= threshold) in rohm_ts_soft_irq()
576 if (++ts->contact_count[1] >= threshold) in rohm_ts_soft_irq()
591 if (++ts->contact_count[2] >= threshold) in rohm_ts_soft_irq()
603 count = ts->contact_count[finger_count]; in rohm_ts_soft_irq()
604 memset(ts->contact_count, 0, sizeof(ts->contact_count)); in rohm_ts_soft_irq()
605 ts->contact_count[finger_count] = count; in rohm_ts_soft_irq()
625 ts->finger_count = finger_count; in rohm_ts_soft_irq()
645 struct device *dev = &client->dev; in rohm_ts_load_firmware()
649 unsigned int retry = 0; in rohm_ts_load_firmware() local
666 if (retry) { in rohm_ts_load_firmware()
669 /* settings for retry */ in rohm_ts_load_firmware()
690 len = fw->size; in rohm_ts_load_firmware()
696 xfer_len, &fw->data[offset]); in rohm_ts_load_firmware()
700 len -= xfer_len; in rohm_ts_load_firmware()
719 error = -EIO; in rohm_ts_load_firmware()
720 } while (++retry <= FIRMWARE_RETRY_MAX); in rohm_ts_load_firmware()
736 return sprintf(buf, "%d\n", !!(ts->setup2 & SWAP_XY)); in swap_xy_show()
740 const char *buf, size_t count) in swap_xy_store() argument
751 error = mutex_lock_interruptible(&ts->input->mutex); in swap_xy_store()
756 ts->setup2 |= SWAP_XY; in swap_xy_store()
758 ts->setup2 &= ~SWAP_XY; in swap_xy_store()
760 if (ts->initialized) in swap_xy_store()
761 error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, in swap_xy_store()
762 ts->setup2); in swap_xy_store()
764 mutex_unlock(&ts->input->mutex); in swap_xy_store()
766 return error ? error : count; in swap_xy_store()
775 return sprintf(buf, "%d\n", !!(ts->setup2 & INV_X)); in inv_x_show()
779 const char *buf, size_t count) in inv_x_store() argument
790 error = mutex_lock_interruptible(&ts->input->mutex); in inv_x_store()
795 ts->setup2 |= INV_X; in inv_x_store()
797 ts->setup2 &= ~INV_X; in inv_x_store()
799 if (ts->initialized) in inv_x_store()
800 error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, in inv_x_store()
801 ts->setup2); in inv_x_store()
803 mutex_unlock(&ts->input->mutex); in inv_x_store()
805 return error ? error : count; in inv_x_store()
814 return sprintf(buf, "%d\n", !!(ts->setup2 & INV_Y)); in inv_y_show()
818 const char *buf, size_t count) in inv_y_store() argument
829 error = mutex_lock_interruptible(&ts->input->mutex); in inv_y_store()
834 ts->setup2 |= INV_Y; in inv_y_store()
836 ts->setup2 &= ~INV_Y; in inv_y_store()
838 if (ts->initialized) in inv_y_store()
840 ts->setup2); in inv_y_store()
842 mutex_unlock(&ts->input->mutex); in inv_y_store()
844 return error ? error : count; in inv_y_store()
864 struct device *dev = &client->dev; in rohm_ts_device_init()
867 disable_irq(client->irq); in rohm_ts_device_init()
880 /* Waiting for the analog warm-up, max. 200usec */ in rohm_ts_device_init()
1043 enable_irq(client->irq); in rohm_ts_device_init()
1055 dev_err(&client->dev, in rohm_ts_power_off()
1063 dev_err(&client->dev, in rohm_ts_power_off()
1072 struct i2c_client *client = ts->client; in rohm_ts_open()
1075 if (!ts->initialized) { in rohm_ts_open()
1076 error = rohm_ts_device_init(client, ts->setup2); in rohm_ts_open()
1078 dev_err(&client->dev, in rohm_ts_open()
1083 ts->initialized = true; in rohm_ts_open()
1093 rohm_ts_power_off(ts->client); in rohm_ts_close()
1095 ts->initialized = false; in rohm_ts_close()
1101 struct device *dev = &client->dev; in rohm_bu21023_i2c_probe()
1106 if (!client->irq) { in rohm_bu21023_i2c_probe()
1108 return -EINVAL; in rohm_bu21023_i2c_probe()
1111 if (!client->adapter->algo->master_xfer) { in rohm_bu21023_i2c_probe()
1112 dev_err(dev, "I2C level transfers not supported\n"); in rohm_bu21023_i2c_probe()
1113 return -EOPNOTSUPP; in rohm_bu21023_i2c_probe()
1123 return -ENOMEM; in rohm_bu21023_i2c_probe()
1125 ts->client = client; in rohm_bu21023_i2c_probe()
1126 ts->setup2 = MAF_1SAMPLE; in rohm_bu21023_i2c_probe()
1131 return -ENOMEM; in rohm_bu21023_i2c_probe()
1133 input->name = BU21023_NAME; in rohm_bu21023_i2c_probe()
1134 input->id.bustype = BUS_I2C; in rohm_bu21023_i2c_probe()
1135 input->open = rohm_ts_open; in rohm_bu21023_i2c_probe()
1136 input->close = rohm_ts_close; in rohm_bu21023_i2c_probe()
1138 ts->input = input; in rohm_bu21023_i2c_probe()
1154 error = devm_request_threaded_irq(dev, client->irq, in rohm_bu21023_i2c_probe()
1156 IRQF_ONESHOT, client->name, ts); in rohm_bu21023_i2c_probe()
1181 MODULE_DEVICE_TABLE(i2c, rohm_bu21023_i2c_id);