a8293.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Allegro A8293 SEC driver
  3. *
  4. * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include "a8293.h"
  17. struct a8293_dev {
  18. struct i2c_client *client;
  19. u8 reg[2];
  20. };
  21. static int a8293_set_voltage(struct dvb_frontend *fe,
  22. enum fe_sec_voltage fe_sec_voltage)
  23. {
  24. struct a8293_dev *dev = fe->sec_priv;
  25. struct i2c_client *client = dev->client;
  26. int ret;
  27. u8 reg0, reg1;
  28. dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage);
  29. switch (fe_sec_voltage) {
  30. case SEC_VOLTAGE_OFF:
  31. /* ENB=0 */
  32. reg0 = 0x10;
  33. break;
  34. case SEC_VOLTAGE_13:
  35. /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
  36. reg0 = 0x31;
  37. break;
  38. case SEC_VOLTAGE_18:
  39. /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
  40. reg0 = 0x38;
  41. break;
  42. default:
  43. ret = -EINVAL;
  44. goto err;
  45. }
  46. if (reg0 != dev->reg[0]) {
  47. ret = i2c_master_send(client, &reg0, 1);
  48. if (ret < 0)
  49. goto err;
  50. dev->reg[0] = reg0;
  51. }
  52. /* TMODE=0, TGATE=1 */
  53. reg1 = 0x82;
  54. if (reg1 != dev->reg[1]) {
  55. ret = i2c_master_send(client, &reg1, 1);
  56. if (ret < 0)
  57. goto err;
  58. dev->reg[1] = reg1;
  59. }
  60. usleep_range(1500, 50000);
  61. return 0;
  62. err:
  63. dev_dbg(&client->dev, "failed=%d\n", ret);
  64. return ret;
  65. }
  66. static int a8293_probe(struct i2c_client *client,
  67. const struct i2c_device_id *id)
  68. {
  69. struct a8293_dev *dev;
  70. struct a8293_platform_data *pdata = client->dev.platform_data;
  71. struct dvb_frontend *fe = pdata->dvb_frontend;
  72. int ret;
  73. u8 buf[2];
  74. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  75. if (!dev) {
  76. ret = -ENOMEM;
  77. goto err;
  78. }
  79. dev->client = client;
  80. /* check if the SEC is there */
  81. ret = i2c_master_recv(client, buf, 2);
  82. if (ret < 0)
  83. goto err_kfree;
  84. /* override frontend ops */
  85. fe->ops.set_voltage = a8293_set_voltage;
  86. fe->sec_priv = dev;
  87. i2c_set_clientdata(client, dev);
  88. dev_info(&client->dev, "Allegro A8293 SEC successfully attached\n");
  89. return 0;
  90. err_kfree:
  91. kfree(dev);
  92. err:
  93. dev_dbg(&client->dev, "failed=%d\n", ret);
  94. return ret;
  95. }
  96. static int a8293_remove(struct i2c_client *client)
  97. {
  98. struct a8293_dev *dev = i2c_get_clientdata(client);
  99. dev_dbg(&client->dev, "\n");
  100. kfree(dev);
  101. return 0;
  102. }
  103. static const struct i2c_device_id a8293_id_table[] = {
  104. {"a8293", 0},
  105. {}
  106. };
  107. MODULE_DEVICE_TABLE(i2c, a8293_id_table);
  108. static struct i2c_driver a8293_driver = {
  109. .driver = {
  110. .name = "a8293",
  111. .suppress_bind_attrs = true,
  112. },
  113. .probe = a8293_probe,
  114. .remove = a8293_remove,
  115. .id_table = a8293_id_table,
  116. };
  117. module_i2c_driver(a8293_driver);
  118. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  119. MODULE_DESCRIPTION("Allegro A8293 SEC driver");
  120. MODULE_LICENSE("GPL");