+unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
+{
+ return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio;
+}
+
+/* Set the currently tuned frequency and account for all possible
+ driver-core side effects of this action. */
+void pvr2_hdw_set_cur_freq(struct pvr2_hdw *hdw,unsigned long val)
+{
+ int mode = 0;
+
+ /* If hdw->automodeswitch_val is set, then we do something clever:
+ Look at the desired frequency and see if it looks like FM or TV.
+ Execute a possible mode switch based on this result. Otherwise
+ we use the current input setting to determine which frequency
+ register we need to adjust. */
+ if (hdw->automodeswitch_val) {
+ /* Note that since FM RADIO frequency range sits *inside*
+ the TV spectrum that we must therefore check the radio
+ range first... */
+ if ((val >= RADIO_MIN_FREQ) && (val <= RADIO_MAX_FREQ)) {
+ mode = 1;
+ } else if ((val >= TV_MIN_FREQ) && (val <= TV_MAX_FREQ)) {
+ mode = 2;
+ }
+ } else {
+ if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+ mode = 1;
+ } else {
+ mode = 2;
+ }
+ }
+
+ switch (mode) {
+ case 1:
+ if (hdw->freqSelector) {
+ /* Swing over to radio frequency selection */
+ hdw->freqSelector = 0;
+ hdw->freqDirty = !0;
+ }
+ if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
+ /* Force switch to radio mode */
+ hdw->input_val = PVR2_CVAL_INPUT_RADIO;
+ hdw->input_dirty = !0;
+ }
+ if (hdw->freqValRadio != val) {
+ hdw->freqValRadio = val;
+ hdw->freqSlotRadio = 0;
+ if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+ hdw->freqDirty = !0;
+ }
+ }
+ break;
+ case 2:
+ if (!(hdw->freqSelector)) {
+ /* Swing over to television frequency selection */
+ hdw->freqSelector = 1;
+ hdw->freqDirty = !0;
+ }
+ if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+ /* Force switch to television mode */
+ hdw->input_val = PVR2_CVAL_INPUT_TV;
+ hdw->input_dirty = !0;
+ }
+ if (hdw->freqValTelevision != val) {
+ hdw->freqValTelevision = val;
+ hdw->freqSlotTelevision = 0;
+ if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
+ hdw->freqDirty = !0;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+