From: Frank Schaefer Date: Sat, 13 Sep 2014 08:52:21 +0000 (-0300) Subject: [media] em28xx: get rid of field has_audio in struct em28xx_audio_mode X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=920f1e4a528a1db01d6822026f653659ecb4983d;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git [media] em28xx: get rid of field has_audio in struct em28xx_audio_mode Field has_audio in struct em28xx_audio_mode is used together with value EM28XX_NO_AC97 of field ac97 to determine the internal type of audio (none/i2s/ac97). This makes the code difficult to understand: !audio_mode.has_audio && audio_mode.ac97 == EM28XX_NO_AC97 => no audio !audio_mode.has_audio && audio_mode.ac97 != EM28XX_NO_AC97 => BUG audio_mode.has_audio && audio_mode.ac97 == EM28XX_NO_AC97 => AC97 audio audio_mode.has_audio && audio_mode.ac97 != EM28XX_NO_AC97 => I2S audio Simplify the whole thing by introducing an enum em28xx_int_audio_type which describes the internal audio type (none, ac97, i2s) and is hooked directly to the device struct. Then get rid of field has_audio in struct em28xx_audio_mode. A follow-up patch will then remove struct em28xx_ac97_mode and finally the whole struct em28xx_audio_mode. Signed-off-by: Frank Schäfer Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index 147d73d4f03a..3413763efd25 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -433,7 +433,7 @@ int em28xx_audio_analog_set(struct em28xx *dev) int ret, i; u8 xclk; - if (!dev->audio_mode.has_audio) + if (dev->int_audio_type == EM28XX_INT_AUDIO_NONE) return 0; /* It is assumed that all devices use master volume for output. @@ -512,25 +512,25 @@ int em28xx_audio_setup(struct em28xx *dev) dev->chip_id == CHIP_ID_EM28174 || dev->chip_id == CHIP_ID_EM28178) { /* Digital only device - don't load any alsa module */ - dev->audio_mode.has_audio = false; + dev->int_audio_type = EM28XX_INT_AUDIO_NONE; dev->usb_audio_type = EM28XX_USB_AUDIO_NONE; return 0; } - dev->audio_mode.has_audio = true; - /* See how this device is configured */ cfg = em28xx_read_reg(dev, EM28XX_R00_CHIPCFG); em28xx_info("Config register raw data: 0x%02x\n", cfg); if (cfg < 0) { /* Register read error? */ cfg = EM28XX_CHIPCFG_AC97; /* Be conservative */ + dev->int_audio_type = EM28XX_INT_AUDIO_AC97; } else if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) == 0x00) { /* The device doesn't have vendor audio at all */ - dev->audio_mode.has_audio = false; + dev->int_audio_type = EM28XX_INT_AUDIO_NONE; dev->usb_audio_type = EM28XX_USB_AUDIO_NONE; return 0; } else if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) != EM28XX_CHIPCFG_AC97) { + dev->int_audio_type = EM28XX_INT_AUDIO_I2S; if (dev->chip_id < CHIP_ID_EM2860 && (cfg & EM28XX_CHIPCFG_AUDIOMASK) == EM2820_CHIPCFG_I2S_1_SAMPRATE) @@ -546,6 +546,8 @@ int em28xx_audio_setup(struct em28xx *dev) /* Skip the code that does AC97 vendor detection */ dev->audio_mode.ac97 = EM28XX_NO_AC97; goto init_audio; + } else { + dev->int_audio_type = EM28XX_INT_AUDIO_AC97; } dev->audio_mode.ac97 = EM28XX_AC97_OTHER; @@ -561,7 +563,7 @@ int em28xx_audio_setup(struct em28xx *dev) dev->audio_mode.ac97 = EM28XX_NO_AC97; if (dev->usb_audio_type == EM28XX_USB_AUDIO_VENDOR) dev->usb_audio_type = EM28XX_USB_AUDIO_NONE; - dev->audio_mode.has_audio = false; + dev->int_audio_type = EM28XX_INT_AUDIO_NONE; goto init_audio; } diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 3642438bc7d4..3284de99fc99 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -1720,7 +1720,7 @@ static int vidioc_querycap(struct file *file, void *priv, else cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE; - if (dev->audio_mode.has_audio) + if (dev->int_audio_type != EM28XX_INT_AUDIO_NONE) cap->device_caps |= V4L2_CAP_AUDIO; if (dev->tuner_type != TUNER_ABSENT) @@ -2514,7 +2514,7 @@ static int em28xx_v4l2_init(struct em28xx *dev) v4l2_disable_ioctl(v4l2->vdev, VIDIOC_G_FREQUENCY); v4l2_disable_ioctl(v4l2->vdev, VIDIOC_S_FREQUENCY); } - if (!dev->audio_mode.has_audio) { + if (dev->int_audio_type == EM28XX_INT_AUDIO_NONE) { v4l2_disable_ioctl(v4l2->vdev, VIDIOC_G_AUDIO); v4l2_disable_ioctl(v4l2->vdev, VIDIOC_S_AUDIO); } @@ -2544,7 +2544,7 @@ static int em28xx_v4l2_init(struct em28xx *dev) v4l2_disable_ioctl(v4l2->vbi_dev, VIDIOC_G_FREQUENCY); v4l2_disable_ioctl(v4l2->vbi_dev, VIDIOC_S_FREQUENCY); } - if (!dev->audio_mode.has_audio) { + if (dev->int_audio_type == EM28XX_INT_AUDIO_NONE) { v4l2_disable_ioctl(v4l2->vbi_dev, VIDIOC_G_AUDIO); v4l2_disable_ioctl(v4l2->vbi_dev, VIDIOC_S_AUDIO); } diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 3fd176f99a23..857ad0c69c84 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -309,7 +309,12 @@ enum em28xx_ac97_mode { struct em28xx_audio_mode { enum em28xx_ac97_mode ac97; - unsigned int has_audio:1; +}; + +enum em28xx_int_audio_type { + EM28XX_INT_AUDIO_NONE = 0, + EM28XX_INT_AUDIO_AC97, + EM28XX_INT_AUDIO_I2S, }; enum em28xx_usb_audio_type { @@ -608,6 +613,7 @@ struct em28xx { unsigned char disconnected:1; /* device has been diconnected */ unsigned int has_video:1; unsigned int is_audio_only:1; + enum em28xx_int_audio_type int_audio_type; enum em28xx_usb_audio_type usb_audio_type; struct em28xx_board board;