a8293.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Allegro A8293 SEC driver
  4. *
  5. * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
  6. */
  7. #include "a8293.h"
  8. struct a8293_dev {
  9. struct i2c_client *client;
  10. u8 reg[2];
  11. };
  12. static int a8293_set_voltage(struct dvb_frontend *fe,
  13. enum fe_sec_voltage fe_sec_voltage)
  14. {
  15. struct a8293_dev *dev = fe->sec_priv;
  16. struct i2c_client *client = dev->client;
  17. int ret;
  18. u8 reg0, reg1;
  19. dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
  20. switch (fe_sec_voltage) {
  21. case SEC_VOLTAGE_OFF:
  22. /* ENB=0 */
  23. reg0 = 0x10;
  24. break;
  25. case SEC_VOLTAGE_13:
  26. /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
  27. reg0 = 0x31;
  28. break;
  29. case SEC_VOLTAGE_18:
  30. /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
  31. reg0 = 0x38;
  32. break;
  33. default:
  34. ret = -EINVAL;
  35. goto err;
  36. }
  37. if (reg0 != dev->reg[0]) {
  38. ret = i2c_master_send(client, &reg0, 1);
  39. if (ret < 0)
  40. goto err;
  41. dev->reg[0] = reg0;
  42. }
  43. /* TMODE=0, TGATE=1 */
  44. reg1 = 0x82;
  45. if (reg1 != dev->reg[1]) {
  46. ret = i2c_master_send(client, &reg1, 1);
  47. if (ret < 0)
  48. goto err;
  49. dev->reg[1] = reg1;
  50. }
  51. usleep_range(1500, 50000);
  52. return 0;
  53. err:
  54. dev_dbg(&client->dev, "failed=%d\n", ret);
  55. return ret;
  56. }
  57. static int a8293_probe(struct i2c_client *client,
  58. const struct i2c_device_id *id)
  59. {
  60. struct a8293_dev *dev;
  61. struct a8293_platform_data *pdata = client->dev.platform_data;
  62. struct dvb_frontend *fe = pdata->dvb_frontend;
  63. int ret;
  64. u8 buf[2];
  65. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  66. if (!dev) {
  67. ret = -ENOMEM;
  68. goto err;
  69. }
  70. dev->client = client;
  71. /* check if the SEC is there */
  72. ret = i2c_master_recv(client, buf, 2);
  73. if (ret < 0)
  74. goto err_kfree;
  75. /* override frontend ops */
  76. fe->ops.set_voltage = a8293_set_voltage;
  77. fe->sec_priv = dev;
  78. i2c_set_clientdata(client, dev);
  79. dev_info(&client->dev, "Allegro A8293 SEC successfully attached\n");
  80. return 0;
  81. err_kfree:
  82. kfree(dev);
  83. err:
  84. dev_dbg(&client->dev, "failed=%d\n", ret);
  85. return ret;
  86. }
  87. static int a8293_remove(struct i2c_client *client)
  88. {
  89. struct a8293_dev *dev = i2c_get_clientdata(client);
  90. dev_dbg(&client->dev, "\n");
  91. kfree(dev);
  92. return 0;
  93. }
  94. static const struct i2c_device_id a8293_id_table[] = {
  95. {"a8293", 0},
  96. {}
  97. };
  98. MODULE_DEVICE_TABLE(i2c, a8293_id_table);
  99. static struct i2c_driver a8293_driver = {
  100. .driver = {
  101. .name = "a8293",
  102. .suppress_bind_attrs = true,
  103. },
  104. .probe = a8293_probe,
  105. .remove = a8293_remove,
  106. .id_table = a8293_id_table,
  107. };
  108. module_i2c_driver(a8293_driver);
  109. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  110. MODULE_DESCRIPTION("Allegro A8293 SEC driver");
  111. MODULE_LICENSE("GPL");