Commit 6cda90b6 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

media: em28xx: improve the logic with sets Xclk and I2C speed

The logic there should be called on two places. Also,
ideally, it should not be modifying the device struct.

So, change the logic accordingly.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent d571b592
...@@ -2685,20 +2685,35 @@ int em28xx_tuner_callback(void *ptr, int component, int command, int arg) ...@@ -2685,20 +2685,35 @@ int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
} }
EXPORT_SYMBOL_GPL(em28xx_tuner_callback); EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
static inline void em28xx_set_model(struct em28xx *dev) static inline void em28xx_set_xclk_i2c_speed(struct em28xx *dev)
{ {
dev->board = em28xx_boards[dev->model]; struct em28xx_board *board = &em28xx_boards[dev->model];
u8 xclk = board->xclk, i2c_speed = board->i2c_speed;
/* Those are the default values for the majority of boards /* Those are the default values for the majority of boards
Use those values if not specified otherwise at boards entry Use those values if not specified otherwise at boards entry
*/ */
if (!dev->board.xclk) if (!xclk)
dev->board.xclk = EM28XX_XCLK_IR_RC5_MODE | xclk = EM28XX_XCLK_IR_RC5_MODE |
EM28XX_XCLK_FREQUENCY_12MHZ; EM28XX_XCLK_FREQUENCY_12MHZ;
if (!dev->board.i2c_speed) em28xx_write_reg(dev, EM28XX_R0F_XCLK, xclk);
dev->board.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
EM28XX_I2C_FREQ_100_KHZ;
if (!i2c_speed)
i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
EM28XX_I2C_FREQ_100_KHZ;
if (!dev->board.is_em2800)
em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, i2c_speed);
msleep(50);
}
static inline void em28xx_set_model(struct em28xx *dev)
{
dev->board = em28xx_boards[dev->model];
em28xx_set_xclk_i2c_speed(dev);
/* Should be initialized early, for I2C to work */ /* Should be initialized early, for I2C to work */
dev->def_i2c_bus = dev->board.def_i2c_bus; dev->def_i2c_bus = dev->board.def_i2c_bus;
...@@ -2741,10 +2756,7 @@ static void em28xx_pre_card_setup(struct em28xx *dev) ...@@ -2741,10 +2756,7 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
{ {
/* Set the initial XCLK and I2C clock values based on the board /* Set the initial XCLK and I2C clock values based on the board
definition */ definition */
em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk & 0x7f); em28xx_set_xclk_i2c_speed(dev);
if (!dev->board.is_em2800)
em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
msleep(50);
/* request some modules */ /* request some modules */
switch (dev->model) { switch (dev->model) {
...@@ -3399,17 +3411,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, ...@@ -3399,17 +3411,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
em28xx_pre_card_setup(dev); em28xx_pre_card_setup(dev);
if (!dev->board.is_em2800) {
/* Resets I2C speed */
retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
if (retval < 0) {
dev_err(&dev->intf->dev,
"%s: em28xx_write_reg failed! retval [%d]\n",
__func__, retval);
return retval;
}
}
rt_mutex_init(&dev->i2c_bus_lock); rt_mutex_init(&dev->i2c_bus_lock);
/* register i2c bus 0 */ /* register i2c bus 0 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment