WSL2-Linux-Kernel/drivers/media/dvb-frontends/a8293.c

279 строки
5.7 KiB
C
Исходник Обычный вид История

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 Based on 3 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version [author] [kishon] [vijay] [abraham] [i] [kishon]@[ti] [com] this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version [author] [graeme] [gregory] [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i] [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema] [hk] [hemahk]@[ti] [com] this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 1105 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Richard Fontana <rfontana@redhat.com> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-27 09:55:06 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Allegro A8293 SEC driver
*
* Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
*/
#include "a8293.h"
#define A8293_FLAG_ODT 0x10
struct a8293_dev {
struct i2c_client *client;
u8 reg[2];
int volt_slew_nanos_per_mv;
};
/*
* When increasing voltage, do so in minimal steps over time, minimizing
* risk of vIN undervoltage.
*/
static int a8293_set_voltage_slew(struct a8293_dev *dev,
struct i2c_client *client,
enum fe_sec_voltage fe_sec_voltage,
int min_nanos_per_mv)
{
int ret;
u8 reg0, reg1;
int new_volt_idx;
const int idx_to_mv[] = {
0, 12709, 13042, 13375, 14042, 15042, 18042, 18709, 19042
};
const u8 idx_to_reg[] = {
0x00, 0x20, 0x21, 0x22, 0x24, 0x27, 0x28, 0x2A, 0x2B
};
int this_volt_idx;
u8 status;
int prev_volt_idx;
dev_dbg(&client->dev, "set_voltage_slew fe_sec_voltage=%d\n",
fe_sec_voltage);
/* Read status register to clear any stale faults. */
ret = i2c_master_recv(client, &status, 1);
if (ret < 0)
goto err;
/* Determine previous voltage */
switch (dev->reg[0] & 0x2F) {
case 0x00:
prev_volt_idx = 0;
break;
case 0x20:
prev_volt_idx = 1;
break;
case 0x21:
prev_volt_idx = 2;
break;
case 0x22:
prev_volt_idx = 3;
break;
case 0x24:
prev_volt_idx = 4;
break;
case 0x27:
prev_volt_idx = 5;
break;
case 0x28:
prev_volt_idx = 6;
break;
case 0x2A:
prev_volt_idx = 7;
break;
case 0x2B:
prev_volt_idx = 8;
break;
default:
prev_volt_idx = 0;
}
/* Determine new voltage */
switch (fe_sec_voltage) {
case SEC_VOLTAGE_OFF:
new_volt_idx = 0;
break;
case SEC_VOLTAGE_13:
new_volt_idx = 2;
break;
case SEC_VOLTAGE_18:
new_volt_idx = 6;
break;
default:
ret = -EINVAL;
goto err;
}
/* Slew to new voltage if new voltage is greater than current voltage */
this_volt_idx = prev_volt_idx;
if (this_volt_idx < new_volt_idx) {
while (this_volt_idx < new_volt_idx) {
int delta_mv = idx_to_mv[this_volt_idx+1] - idx_to_mv[this_volt_idx];
int min_wait_time = delta_mv * min_nanos_per_mv;
reg0 = idx_to_reg[this_volt_idx+1];
reg0 |= A8293_FLAG_ODT;
ret = i2c_master_send(client, &reg0, 1);
if (ret < 0)
goto err;
dev->reg[0] = reg0;
this_volt_idx++;
usleep_range(min_wait_time, min_wait_time * 2);
}
} else { /* Else just set the voltage */
reg0 = idx_to_reg[new_volt_idx];
reg0 |= A8293_FLAG_ODT;
ret = i2c_master_send(client, &reg0, 1);
if (ret < 0)
goto err;
dev->reg[0] = reg0;
}
/* TMODE=0, TGATE=1 */
reg1 = 0x82;
if (reg1 != dev->reg[1]) {
ret = i2c_master_send(client, &reg1, 1);
if (ret < 0)
goto err;
dev->reg[1] = reg1;
}
usleep_range(1500, 5000);
return 0;
err:
dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int a8293_set_voltage_noslew(struct dvb_frontend *fe,
enum fe_sec_voltage fe_sec_voltage)
{
struct a8293_dev *dev = fe->sec_priv;
struct i2c_client *client = dev->client;
int ret;
u8 reg0, reg1;
dev_dbg(&client->dev, "set_voltage_noslew fe_sec_voltage=%d\n",
fe_sec_voltage);
switch (fe_sec_voltage) {
case SEC_VOLTAGE_OFF:
/* ENB=0 */
reg0 = 0x10;
break;
case SEC_VOLTAGE_13:
/* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
reg0 = 0x31;
break;
case SEC_VOLTAGE_18:
/* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
reg0 = 0x38;
break;
default:
ret = -EINVAL;
goto err;
}
if (reg0 != dev->reg[0]) {
ret = i2c_master_send(client, &reg0, 1);
if (ret < 0)
goto err;
dev->reg[0] = reg0;
}
/* TMODE=0, TGATE=1 */
reg1 = 0x82;
if (reg1 != dev->reg[1]) {
ret = i2c_master_send(client, &reg1, 1);
if (ret < 0)
goto err;
dev->reg[1] = reg1;
}
usleep_range(1500, 50000);
return 0;
err:
dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int a8293_set_voltage(struct dvb_frontend *fe,
enum fe_sec_voltage fe_sec_voltage)
{
struct a8293_dev *dev = fe->sec_priv;
struct i2c_client *client = dev->client;
int volt_slew_nanos_per_mv = dev->volt_slew_nanos_per_mv;
dev_dbg(&client->dev, "set_voltage volt_slew_nanos_per_mv=%d\n",
volt_slew_nanos_per_mv);
/* Use slew version if slew rate is set to a sane value */
if (volt_slew_nanos_per_mv > 0 && volt_slew_nanos_per_mv < 1600)
a8293_set_voltage_slew(dev, client, fe_sec_voltage,
volt_slew_nanos_per_mv);
else
a8293_set_voltage_noslew(fe, fe_sec_voltage);
return 0;
}
static int a8293_probe(struct i2c_client *client)
{
struct a8293_dev *dev;
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;
dev->volt_slew_nanos_per_mv = pdata->volt_slew_nanos_per_mv;
/* check if the SEC is there */
ret = i2c_master_recv(client, buf, 2);
if (ret < 0)
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;
}
i2c: Make remove callback return void The value returned by an i2c driver's remove function is mostly ignored. (Only an error message is printed if the value is non-zero that the error is ignored.) So change the prototype of the remove function to return no value. This way driver authors are not tempted to assume that passing an error to the upper layer is a good idea. All drivers are adapted accordingly. There is no intended change of behaviour, all callbacks were prepared to return 0 before. Reviewed-by: Peter Senna Tschudin <peter.senna@gmail.com> Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au> Reviewed-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Crt Mori <cmo@melexis.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Marek Behún <kabel@kernel.org> # for leds-turris-omnia Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Petr Machata <petrm@nvidia.com> # for mlxsw Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com> # for surface3_power Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> # for bmc150-accel-i2c + kxcjk-1013 Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> # for media/* + staging/media/* Acked-by: Miguel Ojeda <ojeda@kernel.org> # for auxdisplay/ht16k33 + auxdisplay/lcd2s Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> # for versaclock5 Reviewed-by: Ajay Gupta <ajayg@nvidia.com> # for ucsi_ccg Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> # for iio Acked-by: Peter Rosin <peda@axentia.se> # for i2c-mux-*, max9860 Acked-by: Adrien Grassein <adrien.grassein@gmail.com> # for lontium-lt8912b Reviewed-by: Jean Delvare <jdelvare@suse.de> # for hwmon, i2c-core and i2c/muxes Acked-by: Corey Minyard <cminyard@mvista.com> # for IPMI Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> # for drivers/power Acked-by: Krzysztof Hałasa <khalasa@piap.pl> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Wolfram Sang <wsa@kernel.org>
2022-08-15 11:02:30 +03:00
static void a8293_remove(struct i2c_client *client)
{
struct a8293_dev *dev = i2c_get_clientdata(client);
dev_dbg(&client->dev, "\n");
kfree(dev);
}
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_new = a8293_probe,
.remove = a8293_remove,
.id_table = a8293_id_table,
};
module_i2c_driver(a8293_driver);
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
MODULE_DESCRIPTION("Allegro A8293 SEC driver");
MODULE_LICENSE("GPL");