2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2011-08-01 11:52:11 +08:00
|
|
|
/*
|
|
|
|
* Allegro A8293 SEC driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "a8293.h"
|
|
|
|
|
2015-04-21 05:16:19 +08:00
|
|
|
struct a8293_dev {
|
2015-04-17 00:28:39 +08:00
|
|
|
struct i2c_client *client;
|
2011-08-01 11:52:11 +08:00
|
|
|
u8 reg[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int a8293_set_voltage(struct dvb_frontend *fe,
|
2015-04-21 05:57:03 +08:00
|
|
|
enum fe_sec_voltage fe_sec_voltage)
|
2011-08-01 11:52:11 +08:00
|
|
|
{
|
2015-04-21 05:16:19 +08:00
|
|
|
struct a8293_dev *dev = fe->sec_priv;
|
|
|
|
struct i2c_client *client = dev->client;
|
2011-08-01 11:52:11 +08:00
|
|
|
int ret;
|
2015-04-21 05:47:44 +08:00
|
|
|
u8 reg0, reg1;
|
2011-08-01 11:52:11 +08:00
|
|
|
|
2015-04-21 05:16:19 +08:00
|
|
|
dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
|
2011-08-01 11:52:11 +08:00
|
|
|
|
|
|
|
switch (fe_sec_voltage) {
|
|
|
|
case SEC_VOLTAGE_OFF:
|
|
|
|
/* ENB=0 */
|
2015-04-21 05:47:44 +08:00
|
|
|
reg0 = 0x10;
|
2011-08-01 11:52:11 +08:00
|
|
|
break;
|
|
|
|
case SEC_VOLTAGE_13:
|
|
|
|
/* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
|
2015-04-21 05:47:44 +08:00
|
|
|
reg0 = 0x31;
|
2011-08-01 11:52:11 +08:00
|
|
|
break;
|
|
|
|
case SEC_VOLTAGE_18:
|
|
|
|
/* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
|
2015-04-21 05:47:44 +08:00
|
|
|
reg0 = 0x38;
|
2011-08-01 11:52:11 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
2012-09-28 16:37:22 +08:00
|
|
|
}
|
2015-04-21 05:47:44 +08:00
|
|
|
if (reg0 != dev->reg[0]) {
|
|
|
|
ret = i2c_master_send(client, ®0, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
dev->reg[0] = reg0;
|
|
|
|
}
|
2011-08-01 11:52:11 +08:00
|
|
|
|
2015-04-21 05:47:44 +08:00
|
|
|
/* TMODE=0, TGATE=1 */
|
|
|
|
reg1 = 0x82;
|
|
|
|
if (reg1 != dev->reg[1]) {
|
|
|
|
ret = i2c_master_send(client, ®1, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
dev->reg[1] = reg1;
|
|
|
|
}
|
2011-08-01 11:52:11 +08:00
|
|
|
|
2013-02-25 19:24:18 +08:00
|
|
|
usleep_range(1500, 50000);
|
2015-04-21 05:16:19 +08:00
|
|
|
return 0;
|
2011-08-01 11:52:11 +08:00
|
|
|
err:
|
2015-04-21 05:16:19 +08:00
|
|
|
dev_dbg(&client->dev, "failed=%d\n", ret);
|
2011-08-01 11:52:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:28:39 +08:00
|
|
|
static int a8293_probe(struct i2c_client *client,
|
2015-04-21 04:39:33 +08:00
|
|
|
const struct i2c_device_id *id)
|
2015-04-17 00:28:39 +08:00
|
|
|
{
|
2015-04-21 05:16:19 +08:00
|
|
|
struct a8293_dev *dev;
|
2015-04-17 00:28:39 +08:00
|
|
|
struct a8293_platform_data *pdata = client->dev.platform_data;
|
|
|
|
struct dvb_frontend *fe = pdata->dvb_frontend;
|
|
|
|
int ret;
|
|
|
|
u8 buf[2];
|
|
|
|
|
|
|
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
|
|
|
if (!dev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->client = client;
|
|
|
|
|
|
|
|
/* check if the SEC is there */
|
2015-04-21 05:16:19 +08:00
|
|
|
ret = i2c_master_recv(client, buf, 2);
|
|
|
|
if (ret < 0)
|
2015-04-17 00:28:39 +08:00
|
|
|
goto err_kfree;
|
|
|
|
|
|
|
|
/* override frontend ops */
|
|
|
|
fe->ops.set_voltage = a8293_set_voltage;
|
|
|
|
fe->sec_priv = dev;
|
|
|
|
i2c_set_clientdata(client, dev);
|
|
|
|
|
|
|
|
dev_info(&client->dev, "Allegro A8293 SEC successfully attached\n");
|
|
|
|
return 0;
|
|
|
|
err_kfree:
|
|
|
|
kfree(dev);
|
|
|
|
err:
|
|
|
|
dev_dbg(&client->dev, "failed=%d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int a8293_remove(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct a8293_dev *dev = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "\n");
|
|
|
|
|
|
|
|
kfree(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id a8293_id_table[] = {
|
|
|
|
{"a8293", 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, a8293_id_table);
|
|
|
|
|
|
|
|
static struct i2c_driver a8293_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "a8293",
|
|
|
|
.suppress_bind_attrs = true,
|
|
|
|
},
|
|
|
|
.probe = a8293_probe,
|
|
|
|
.remove = a8293_remove,
|
|
|
|
.id_table = a8293_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(a8293_driver);
|
|
|
|
|
2011-08-01 11:52:11 +08:00
|
|
|
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
|
|
|
|
MODULE_DESCRIPTION("Allegro A8293 SEC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|