~mil/ppbbq10

d1a65899ae1cda06d16ae7c29ee93322c2e0d938 — Miles Alan 3 years ago 16a4f21
Rename to ppbbq10; use 3rd I2C adapter rather then using module device table
2 files changed, 56 insertions(+), 55 deletions(-)

M Makefile
R bbq10pmod.c => ppbbq10.c
M Makefile => Makefile +1 -1
@@ 1,4 1,4 @@
MODULE_NAME := bbq10pmod
MODULE_NAME := ppbbq10

obj-m := $(MODULE_NAME).o


R bbq10pmod.c => ppbbq10.c +55 -54
@@ 99,13 99,23 @@ static unsigned short keycodes[NUM_KEYCODES] = {
	['\n'] = KEY_ENTER,
};

struct bbq10pmod_data {
struct ppbbq10_data {
	unsigned short keycode[NUM_KEYCODES];
	struct i2c_client *client;
	struct input_dev *input;
};

static int bbq10pmod_write_reg(struct bbq10pmod_data *drv_data, u8 reg)
static struct i2c_adapter *adapter;
static struct i2c_client *client;
static struct i2c_board_info ppbbq10_i2c_board_info[] __initdata = {
	{ I2C_BOARD_INFO("ppbbq10", 0x1f), /*.irq = gpio_to_irq(11)*/ }
};
static const struct i2c_device_id ppbbq10_id[] = {
	{ "ppbbq10", 0, }
};


static int ppbbq10_write_reg(struct ppbbq10_data *drv_data, u8 reg)
{
	struct i2c_client *client = drv_data->client;
	int error;


@@ 125,7 135,7 @@ static int bbq10pmod_write_reg(struct bbq10pmod_data *drv_data, u8 reg)
	return 0;
}

static int bbq10pmod_write_data(struct bbq10pmod_data *drv_data, u8 reg, const u8 *buf, u8 len)
static int ppbbq10_write_data(struct ppbbq10_data *drv_data, u8 reg, const u8 *buf, u8 len)
{
	struct i2c_client *client = drv_data->client;
	int error;


@@ 148,7 158,7 @@ static int bbq10pmod_write_data(struct bbq10pmod_data *drv_data, u8 reg, const u
	return 0;
}

static int bbq10pmod_read_reg(struct bbq10pmod_data *drv_data, u8 reg, u8 *buf, u8 len)
static int ppbbq10_read_reg(struct ppbbq10_data *drv_data, u8 reg, u8 *buf, u8 len)
{
	struct i2c_client *client = drv_data->client;
	int error;


@@ 169,14 179,14 @@ static int bbq10pmod_read_reg(struct bbq10pmod_data *drv_data, u8 reg, u8 *buf, 
	return 0;
}

static void bbq10pmod_update_locks(struct bbq10pmod_data *drv_data)
static void ppbbq10_update_locks(struct ppbbq10_data *drv_data)
{
	struct input_dev *input = drv_data->input;
	struct i2c_client *client = drv_data->client;
	u8 data;
	int error;

	error = bbq10pmod_read_reg(drv_data, REG_KEY, &data, sizeof(u8));
	error = ppbbq10_read_reg(drv_data, REG_KEY, &data, sizeof(u8));
	if (error < 0) {
		dev_err(&client->dev, "%s failed to read REG_KEY, error: %d\n",
			__func__, error);


@@ 191,7 201,7 @@ static void bbq10pmod_update_locks(struct bbq10pmod_data *drv_data)
	input_sync(input);
}

static void bbq10pmod_read_fifo(struct bbq10pmod_data *drv_data)
static void ppbbq10_read_fifo(struct ppbbq10_data *drv_data)
{
	struct input_dev *input = drv_data->input;
	struct i2c_client *client = drv_data->client;


@@ 200,7 210,7 @@ static void bbq10pmod_read_fifo(struct bbq10pmod_data *drv_data)
	u8 count;
	int error;

	error = bbq10pmod_read_reg(drv_data, REG_KEY, data, sizeof(u8));
	error = ppbbq10_read_reg(drv_data, REG_KEY, data, sizeof(u8));
	if (error < 0) {
		dev_err(&client->dev, "%s failed to read REG_KEY, error: %d\n",
			__func__, error);


@@ 212,7 222,7 @@ static void bbq10pmod_read_fifo(struct bbq10pmod_data *drv_data)
	count = (data[0] & KEY_COUNT_MASK);

	while (count > 0) {
		error = bbq10pmod_read_reg(drv_data, REG_FIF, data, sizeof(u8) * 2);
		error = ppbbq10_read_reg(drv_data, REG_FIF, data, sizeof(u8) * 2);
		if (error < 0) {
			dev_err(&client->dev, "%s failed to read REG_FIF, error: %d\n",
				__func__, error);


@@ 239,16 249,16 @@ static void bbq10pmod_read_fifo(struct bbq10pmod_data *drv_data)
	input_sync(input);
}

static irqreturn_t bbq10pmod_irq_handler(int irq, void *dev_id)
static irqreturn_t ppbbq10_irq_handler(int irq, void *dev_id)
{
	struct bbq10pmod_data *drv_data = dev_id;
	struct ppbbq10_data *drv_data = dev_id;
	struct i2c_client *client = drv_data->client;
	int error;
	u8 reg;

	pr_debug("%s fired\n", __func__);

	error = bbq10pmod_read_reg(drv_data, REG_INT, &reg, sizeof(u8));
	error = ppbbq10_read_reg(drv_data, REG_INT, &reg, sizeof(u8));
	if (error < 0) {
		dev_err(&client->dev, "%s: failed to read KEY: %d\n",
			__func__, error);


@@ 264,13 274,13 @@ static irqreturn_t bbq10pmod_irq_handler(int irq, void *dev_id)
		dev_warn(&client->dev, "overflow occurred\n");

	if (reg & INT_CAPSLOCK || reg & INT_NUMLOCK)
		bbq10pmod_update_locks(drv_data);
		ppbbq10_update_locks(drv_data);

	if (reg & INT_KEY)
		bbq10pmod_read_fifo(drv_data);
		ppbbq10_read_fifo(drv_data);

	reg = 0x00;
	error = bbq10pmod_write_data(drv_data, REG_INT, &reg, sizeof(reg));
	error = ppbbq10_write_data(drv_data, REG_INT, &reg, sizeof(reg));
	if (error < 0)
		dev_err(&client->dev, "%s: failed to clear REG_INT, error: %d\n",
			__func__, error);


@@ 278,18 288,18 @@ static irqreturn_t bbq10pmod_irq_handler(int irq, void *dev_id)
	return IRQ_HANDLED;
}

static int bbq10pmod_backlight_update_status(struct backlight_device *bd)
static int ppbbq10_backlight_update_status(struct backlight_device *bd)
{
	const struct backlight_properties *p = &bd->props;
	const u8 intensity = (p->power == FB_BLANK_UNBLANK) ? p->brightness : 0;
	struct bbq10pmod_data *drv_data = dev_get_drvdata(&bd->dev);
	struct ppbbq10_data *drv_data = dev_get_drvdata(&bd->dev);

	return bbq10pmod_write_data(drv_data, REG_BKL, &intensity, sizeof(intensity));
	return ppbbq10_write_data(drv_data, REG_BKL, &intensity, sizeof(intensity));
}

static const struct backlight_ops backlight_ops = {
	.options		= BL_CORE_SUSPENDRESUME,
	.update_status	= bbq10pmod_backlight_update_status,
	.update_status	= ppbbq10_backlight_update_status,
};

static struct backlight_properties backlight_props = {


@@ 298,10 308,10 @@ static struct backlight_properties backlight_props = {
	.brightness		= 127,
};

static int bbq10pmod_probe(struct i2c_client *client, const struct i2c_device_id *id)
static int ppbbq10_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct device *dev = &client->dev;
	struct bbq10pmod_data *drv_data;
	struct ppbbq10_data *drv_data;
	struct backlight_device *bd;
	struct input_dev *input;
	int error;


@@ 315,13 325,13 @@ static int bbq10pmod_probe(struct i2c_client *client, const struct i2c_device_id
	drv_data->client = client;
	memcpy(drv_data->keycode, keycodes, sizeof(drv_data->keycode));

	error = bbq10pmod_write_reg(drv_data, REG_RST);
	error = ppbbq10_write_reg(drv_data, REG_RST);
	if (error)
		return -ENODEV;

	msleep(100);

	error = bbq10pmod_read_reg(drv_data, REG_VER, &reg, sizeof(reg));
	error = ppbbq10_read_reg(drv_data, REG_VER, &reg, sizeof(reg));
	if (error)
		return -ENODEV;



@@ 329,7 339,7 @@ static int bbq10pmod_probe(struct i2c_client *client, const struct i2c_device_id

	reg = CFG_OVERFLOW_ON | CFG_OVERFLOW_INT | CFG_CAPSLOCK_INT |
			CFG_NUMLOCK_INT | CFG_KEY_INT | CFG_REPORT_MODS;
	error = bbq10pmod_write_data(drv_data, REG_CFG, &reg, sizeof(reg));
	error = ppbbq10_write_data(drv_data, REG_CFG, &reg, sizeof(reg));
	if (error)
		return -ENODEV;



@@ 370,7 380,7 @@ static int bbq10pmod_probe(struct i2c_client *client, const struct i2c_device_id
	input_set_capability(input, EV_MSC, MSC_SCAN);

	error = devm_request_threaded_irq(dev, client->irq,
										NULL, bbq10pmod_irq_handler,
										NULL, ppbbq10_irq_handler,
										IRQF_SHARED | IRQF_ONESHOT,
										client->name, drv_data);
	if (error) {


@@ 387,39 397,30 @@ static int bbq10pmod_probe(struct i2c_client *client, const struct i2c_device_id
	return 0;
}

static const struct i2c_device_id bbq10pmod_id[] = {
	{ "bbq10pmod", 0, },
	{ }
};
MODULE_DEVICE_TABLE(i2c, bbq10pmod_id);

static const struct of_device_id bbq10pmod_dt_ids[] = {
	{ .compatible = "arturo182,bbq10pmod", },
	{ }
};
MODULE_DEVICE_TABLE(of, bbq10pmod_dt_ids);

static struct i2c_driver bbq10pmod_driver = {
	.driver = {
		.name = "bbq10pmod",
		.of_match_table = bbq10pmod_dt_ids,
	},
	.probe		= bbq10pmod_probe,
	.id_table	= bbq10pmod_id,
};

static int __init bbq10pmod_init(void)
static int __init ppbbq10_init(void)
{
	return i2c_add_driver(&bbq10pmod_driver);
	adapter = i2c_get_adapter(3);
	printk(KERN_INFO "Initialize ppbq10 kernel module.\n");
	if (!adapter) {
		printk(KERN_INFO "Error acquiring i2c adapter 3.\n");
		return -1;
	}
	client = i2c_new_client_device(adapter, ppbbq10_i2c_board_info);
	//client->irq = gpio_to_irq(2);
	return 0;
}
subsys_initcall(bbq10pmod_init);

static void __exit bbq10pmod_exit(void)

static void __exit ppbbq10_exit(void)
{
	i2c_del_driver(&bbq10pmod_driver);
	printk(KERN_INFO "Unregister ppbbq10 kernel module.\n");
	i2c_unregister_device(client);
	/*i2c_del_driver(&ppbbq10_driver);*/
}
module_exit(bbq10pmod_exit);

MODULE_AUTHOR("arturo182 <arturo182@tlen.pl>");
MODULE_DESCRIPTION("Keyboard driver for BBQ10 PMOD");

module_init(ppbbq10_init);
module_exit(ppbbq10_exit);
MODULE_AUTHOR("arturo182 <arturo182@tlen.pl> & miles alan <m@milesalan.com>");
MODULE_DESCRIPTION("Keyboard driver for BBQ10 PMOD that works OOB with the Pinephone");
MODULE_LICENSE("GPL");