aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tuner-core.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2011-02-15 07:27:03 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-21 19:32:03 -0400
commit0eec66c0dfc1b066e6addbc6af755c779f65fd87 (patch)
tree1f828988ea18d0c4ae906c8a440ddef6123ce949 /drivers/media/video/tuner-core.c
parenta2894e3f8ed691b4873c8122e66902fbf0e78e0b (diff)
[media] tuner-core: Rearrange some functions to better document
Group a few functions together and add/fix comments for each block of the driver. This is just a cleanup patch meant to improve driver readability. No functional changes in this patch. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tuner-core.c')
-rw-r--r--drivers/media/video/tuner-core.c168
1 files changed, 90 insertions, 78 deletions
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 2c7fe18cedeb..a91a29978f9c 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -251,7 +251,7 @@ static struct analog_demod_ops tuner_analog_ops = {
251}; 251};
252 252
253/* 253/*
254 * Functions to select between radio and TV and tuner probe functions 254 * Functions to select between radio and TV and tuner probe/remove functions
255 */ 255 */
256 256
257/** 257/**
@@ -698,6 +698,75 @@ static int tuner_remove(struct i2c_client *client)
698} 698}
699 699
700/* 700/*
701 * Functions to switch between Radio and TV
702 *
703 * A few cards have a separate I2C tuner for radio. Those routines
704 * take care of switching between TV/Radio mode, filtering only the
705 * commands that apply to the Radio or TV tuner.
706 */
707
708/**
709 * check_mode - Verify if tuner supports the requested mode
710 * @t: a pointer to the module's internal struct_tuner
711 *
712 * This function checks if the tuner is capable of tuning analog TV,
713 * digital TV or radio, depending on what the caller wants. If the
714 * tuner can't support that mode, it returns -EINVAL. Otherwise, it
715 * returns 0.
716 * This function is needed for boards that have a separate tuner for
717 * radio (like devices with tea5767).
718 */
719static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
720{
721 if ((1 << mode & t->mode_mask) == 0)
722 return -EINVAL;
723
724 return 0;
725}
726
727/**
728 * set_mode_freq - Switch tuner to other mode.
729 * @client: struct i2c_client pointer
730 * @t: a pointer to the module's internal struct_tuner
731 * @mode: enum v4l2_type (radio or TV)
732 * @freq: frequency to set (0 means to use the previous one)
733 *
734 * If tuner doesn't support the needed mode (radio or TV), prints a
735 * debug message and returns -EINVAL, changing its state to standby.
736 * Otherwise, changes the state and sets frequency to the last value, if
737 * the tuner can sleep or if it supports both Radio and TV.
738 */
739static int set_mode_freq(struct i2c_client *client, struct tuner *t,
740 enum v4l2_tuner_type mode, unsigned int freq)
741{
742 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
743
744 if (mode != t->mode) {
745 if (check_mode(t, mode) == -EINVAL) {
746 tuner_dbg("Tuner doesn't support mode %d. "
747 "Putting tuner to sleep\n", mode);
748 t->standby = true;
749 if (analog_ops->standby)
750 analog_ops->standby(&t->fe);
751 return -EINVAL;
752 }
753 t->mode = mode;
754 tuner_dbg("Changing to mode %d\n", mode);
755 }
756 if (t->mode == V4L2_TUNER_RADIO) {
757 if (freq)
758 t->radio_freq = freq;
759 set_radio_freq(client, t->radio_freq);
760 } else {
761 if (freq)
762 t->tv_freq = freq;
763 set_tv_freq(client, t->tv_freq);
764 }
765
766 return 0;
767}
768
769/*
701 * Functions that are specific for TV mode 770 * Functions that are specific for TV mode
702 */ 771 */
703 772
@@ -925,66 +994,9 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
925 analog_ops->set_params(&t->fe, &params); 994 analog_ops->set_params(&t->fe, &params);
926} 995}
927 996
928/** 997/*
929 * check_mode - Verify if tuner supports the requested mode 998 * Debug function for reporting tuner status to userspace
930 * @t: a pointer to the module's internal struct_tuner
931 *
932 * This function checks if the tuner is capable of tuning analog TV,
933 * digital TV or radio, depending on what the caller wants. If the
934 * tuner can't support that mode, it returns -EINVAL. Otherwise, it
935 * returns 0.
936 * This function is needed for boards that have a separate tuner for
937 * radio (like devices with tea5767).
938 */
939static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode)
940{
941 if ((1 << mode & t->mode_mask) == 0)
942 return -EINVAL;
943
944 return 0;
945}
946
947/**
948 * set_mode_freq - Switch tuner to other mode.
949 * @client: struct i2c_client pointer
950 * @t: a pointer to the module's internal struct_tuner
951 * @mode: enum v4l2_type (radio or TV)
952 * @freq: frequency to set (0 means to use the previous one)
953 *
954 * If tuner doesn't support the needed mode (radio or TV), prints a
955 * debug message and returns -EINVAL, changing internal state to T_STANDBY.
956 * Otherwise, changes the state and sets frequency to the last value, if
957 * the tuner can sleep or if it supports both Radio and TV.
958 */ 999 */
959static int set_mode_freq(struct i2c_client *client, struct tuner *t,
960 enum v4l2_tuner_type mode, unsigned int freq)
961{
962 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
963
964 if (mode != t->mode) {
965 if (check_mode(t, mode) == -EINVAL) {
966 tuner_dbg("Tuner doesn't support mode %d. "
967 "Putting tuner to sleep\n", mode);
968 t->standby = true;
969 if (analog_ops->standby)
970 analog_ops->standby(&t->fe);
971 return -EINVAL;
972 }
973 t->mode = mode;
974 tuner_dbg("Changing to mode %d\n", mode);
975 }
976 if (t->mode == V4L2_TUNER_RADIO) {
977 if (freq)
978 t->radio_freq = freq;
979 set_radio_freq(client, t->radio_freq);
980 } else {
981 if (freq)
982 t->tv_freq = freq;
983 set_tv_freq(client, t->tv_freq);
984 }
985
986 return 0;
987}
988 1000
989/** 1001/**
990 * tuner_status - Dumps the current tuner status at dmesg 1002 * tuner_status - Dumps the current tuner status at dmesg
@@ -1040,6 +1052,24 @@ static void tuner_status(struct dvb_frontend *fe)
1040 analog_ops->has_signal(fe)); 1052 analog_ops->has_signal(fe));
1041} 1053}
1042 1054
1055/*
1056 * Function to splicitly change mode to radio. Probably not needed anymore
1057 */
1058
1059static int tuner_s_radio(struct v4l2_subdev *sd)
1060{
1061 struct tuner *t = to_tuner(sd);
1062 struct i2c_client *client = v4l2_get_subdevdata(sd);
1063
1064 if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL)
1065 return 0;
1066 return 0;
1067}
1068
1069/*
1070 * Tuner callbacks to handle userspace ioctl's
1071 */
1072
1043/** 1073/**
1044 * tuner_s_power - controls the power state of the tuner 1074 * tuner_s_power - controls the power state of the tuner
1045 * @sd: pointer to struct v4l2_subdev 1075 * @sd: pointer to struct v4l2_subdev
@@ -1061,24 +1091,6 @@ static int tuner_s_power(struct v4l2_subdev *sd, int on)
1061 return 0; 1091 return 0;
1062} 1092}
1063 1093
1064/*
1065 * Function to splicitly change mode to radio. Probably not needed anymore
1066 */
1067
1068static int tuner_s_radio(struct v4l2_subdev *sd)
1069{
1070 struct tuner *t = to_tuner(sd);
1071 struct i2c_client *client = v4l2_get_subdevdata(sd);
1072
1073 if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL)
1074 return 0;
1075 return 0;
1076}
1077
1078/*
1079 * Tuner callbacks to handle userspace ioctl's
1080 */
1081
1082static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 1094static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1083{ 1095{
1084 struct tuner *t = to_tuner(sd); 1096 struct tuner *t = to_tuner(sd);