Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
0004  *
0005  *   Lowlevel functions for ESI Juli@ cards
0006  *
0007  *  Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
0008  *                2008 Pavel Hofman <dustin@seznam.cz>
0009  */
0010 
0011 #include <linux/delay.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/init.h>
0014 #include <linux/slab.h>
0015 #include <linux/string.h>
0016 #include <sound/core.h>
0017 #include <sound/tlv.h>
0018 
0019 #include "ice1712.h"
0020 #include "envy24ht.h"
0021 #include "juli.h"
0022 
0023 struct juli_spec {
0024     struct ak4114 *ak4114;
0025     unsigned int analog:1;
0026 };
0027 
0028 /*
0029  * chip addresses on I2C bus
0030  */
0031 #define AK4114_ADDR     0x20        /* S/PDIF receiver */
0032 #define AK4358_ADDR     0x22        /* DAC */
0033 
0034 /*
0035  * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is
0036  * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency
0037  * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx.
0038  *
0039  * The clock circuitry is supplied by the two ice1724 crystals. This
0040  * arrangement allows to generate independent clock signal for AK4114's input
0041  * rate detection circuit. As a result, Juli, unlike most other
0042  * ice1724+ak4114-based cards, detects spdif input rate correctly.
0043  * This fact is applied in the driver, allowing to modify PCM stream rate
0044  * parameter according to the actual input rate.
0045  *
0046  * Juli uses the remaining three stereo-channels of its DAC to optionally
0047  * monitor analog input, digital input, and digital output. The corresponding
0048  * I2S signals are routed by Xilinx, controlled by GPIOs.
0049  *
0050  * The master mute is implemented using output muting transistors (GPIO) in
0051  * combination with smuting the DAC.
0052  *
0053  * The card itself has no HW master volume control, implemented using the
0054  * vmaster control.
0055  *
0056  * TODO:
0057  * researching and fixing the input monitors
0058  */
0059 
0060 /*
0061  * GPIO pins
0062  */
0063 #define GPIO_FREQ_MASK      (3<<0)
0064 #define GPIO_FREQ_32KHZ     (0<<0)
0065 #define GPIO_FREQ_44KHZ     (1<<0)
0066 #define GPIO_FREQ_48KHZ     (2<<0)
0067 #define GPIO_MULTI_MASK     (3<<2)
0068 #define GPIO_MULTI_4X       (0<<2)
0069 #define GPIO_MULTI_2X       (1<<2)
0070 #define GPIO_MULTI_1X       (2<<2)      /* also external */
0071 #define GPIO_MULTI_HALF     (3<<2)
0072 #define GPIO_INTERNAL_CLOCK (1<<4)      /* 0 = external, 1 = internal */
0073 #define GPIO_CLOCK_MASK     (1<<4)
0074 #define GPIO_ANALOG_PRESENT (1<<5)      /* RO only: 0 = present */
0075 #define GPIO_RXMCLK_SEL     (1<<7)      /* must be 0 */
0076 #define GPIO_AK5385A_CKS0   (1<<8)
0077 #define GPIO_AK5385A_DFS1   (1<<9)
0078 #define GPIO_AK5385A_DFS0   (1<<10)
0079 #define GPIO_DIGOUT_MONITOR (1<<11)     /* 1 = active */
0080 #define GPIO_DIGIN_MONITOR  (1<<12)     /* 1 = active */
0081 #define GPIO_ANAIN_MONITOR  (1<<13)     /* 1 = active */
0082 #define GPIO_AK5385A_CKS1   (1<<14)     /* must be 0 */
0083 #define GPIO_MUTE_CONTROL   (1<<15)     /* output mute, 1 = muted */
0084 
0085 #define GPIO_RATE_MASK      (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \
0086         GPIO_CLOCK_MASK)
0087 #define GPIO_AK5385A_MASK   (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \
0088         GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1)
0089 
0090 #define JULI_PCM_RATE   (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
0091         SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
0092         SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
0093         SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
0094         SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
0095 
0096 #define GPIO_RATE_16000     (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \
0097         GPIO_INTERNAL_CLOCK)
0098 #define GPIO_RATE_22050     (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \
0099         GPIO_INTERNAL_CLOCK)
0100 #define GPIO_RATE_24000     (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \
0101         GPIO_INTERNAL_CLOCK)
0102 #define GPIO_RATE_32000     (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \
0103         GPIO_INTERNAL_CLOCK)
0104 #define GPIO_RATE_44100     (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \
0105         GPIO_INTERNAL_CLOCK)
0106 #define GPIO_RATE_48000     (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \
0107         GPIO_INTERNAL_CLOCK)
0108 #define GPIO_RATE_64000     (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \
0109         GPIO_INTERNAL_CLOCK)
0110 #define GPIO_RATE_88200     (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \
0111         GPIO_INTERNAL_CLOCK)
0112 #define GPIO_RATE_96000     (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \
0113         GPIO_INTERNAL_CLOCK)
0114 #define GPIO_RATE_176400    (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \
0115         GPIO_INTERNAL_CLOCK)
0116 #define GPIO_RATE_192000    (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \
0117         GPIO_INTERNAL_CLOCK)
0118 
0119 /*
0120  * Initial setup of the conversion array GPIO <-> rate
0121  */
0122 static const unsigned int juli_rates[] = {
0123     16000, 22050, 24000, 32000,
0124     44100, 48000, 64000, 88200,
0125     96000, 176400, 192000,
0126 };
0127 
0128 static const unsigned int gpio_vals[] = {
0129     GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000,
0130     GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200,
0131     GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000,
0132 };
0133 
0134 static const struct snd_pcm_hw_constraint_list juli_rates_info = {
0135     .count = ARRAY_SIZE(juli_rates),
0136     .list = juli_rates,
0137     .mask = 0,
0138 };
0139 
0140 static int get_gpio_val(int rate)
0141 {
0142     int i;
0143     for (i = 0; i < ARRAY_SIZE(juli_rates); i++)
0144         if (juli_rates[i] == rate)
0145             return gpio_vals[i];
0146     return 0;
0147 }
0148 
0149 static void juli_ak4114_write(void *private_data, unsigned char reg,
0150                 unsigned char val)
0151 {
0152     snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR,
0153                 reg, val);
0154 }
0155 
0156 static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
0157 {
0158     return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data,
0159                     AK4114_ADDR, reg);
0160 }
0161 
0162 /*
0163  * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate
0164  * to the external rate
0165  */
0166 static void juli_spdif_in_open(struct snd_ice1712 *ice,
0167                 struct snd_pcm_substream *substream)
0168 {
0169     struct juli_spec *spec = ice->spec;
0170     struct snd_pcm_runtime *runtime = substream->runtime;
0171     int rate;
0172 
0173     if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
0174             !ice->is_spdif_master(ice))
0175         return;
0176     rate = snd_ak4114_external_rate(spec->ak4114);
0177     if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
0178         runtime->hw.rate_min = rate;
0179         runtime->hw.rate_max = rate;
0180     }
0181 }
0182 
0183 /*
0184  * AK4358 section
0185  */
0186 
0187 static void juli_akm_lock(struct snd_akm4xxx *ak, int chip)
0188 {
0189 }
0190 
0191 static void juli_akm_unlock(struct snd_akm4xxx *ak, int chip)
0192 {
0193 }
0194 
0195 static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
0196                unsigned char addr, unsigned char data)
0197 {
0198     struct snd_ice1712 *ice = ak->private_data[0];
0199      
0200     if (snd_BUG_ON(chip))
0201         return;
0202     snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data);
0203 }
0204 
0205 /*
0206  * change the rate of envy24HT, AK4358, AK5385
0207  */
0208 static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
0209 {
0210     unsigned char old, tmp, ak4358_dfs;
0211     unsigned int ak5385_pins, old_gpio, new_gpio;
0212     struct snd_ice1712 *ice = ak->private_data[0];
0213     struct juli_spec *spec = ice->spec;
0214 
0215     if (rate == 0)  /* no hint - S/PDIF input is master or the new spdif
0216                input rate undetected, simply return */
0217         return;
0218 
0219     /* adjust DFS on codecs */
0220     if (rate > 96000)  {
0221         ak4358_dfs = 2;
0222         ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0;
0223     } else if (rate > 48000) {
0224         ak4358_dfs = 1;
0225         ak5385_pins = GPIO_AK5385A_DFS0;
0226     } else {
0227         ak4358_dfs = 0;
0228         ak5385_pins = 0;
0229     }
0230     /* AK5385 first, since it requires cold reset affecting both codecs */
0231     old_gpio = ice->gpio.get_data(ice);
0232     new_gpio =  (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
0233     /* dev_dbg(ice->card->dev, "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
0234         new_gpio); */
0235     ice->gpio.set_data(ice, new_gpio);
0236 
0237     /* cold reset */
0238     old = inb(ICEMT1724(ice, AC97_CMD));
0239     outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
0240     udelay(1);
0241     outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
0242 
0243     /* AK4358 */
0244     /* set new value, reset DFS */
0245     tmp = snd_akm4xxx_get(ak, 0, 2);
0246     snd_akm4xxx_reset(ak, 1);
0247     tmp = snd_akm4xxx_get(ak, 0, 2);
0248     tmp &= ~(0x03 << 4);
0249     tmp |= ak4358_dfs << 4;
0250     snd_akm4xxx_set(ak, 0, 2, tmp);
0251     snd_akm4xxx_reset(ak, 0);
0252 
0253     /* reinit ak4114 */
0254     snd_ak4114_reinit(spec->ak4114);
0255 }
0256 
0257 #define AK_DAC(xname, xch)  { .name = xname, .num_channels = xch }
0258 #define PCM_VOLUME      "PCM Playback Volume"
0259 #define MONITOR_AN_IN_VOLUME    "Monitor Analog In Volume"
0260 #define MONITOR_DIG_IN_VOLUME   "Monitor Digital In Volume"
0261 #define MONITOR_DIG_OUT_VOLUME  "Monitor Digital Out Volume"
0262 
0263 static const struct snd_akm4xxx_dac_channel juli_dac[] = {
0264     AK_DAC(PCM_VOLUME, 2),
0265     AK_DAC(MONITOR_AN_IN_VOLUME, 2),
0266     AK_DAC(MONITOR_DIG_OUT_VOLUME, 2),
0267     AK_DAC(MONITOR_DIG_IN_VOLUME, 2),
0268 };
0269 
0270 
0271 static const struct snd_akm4xxx akm_juli_dac = {
0272     .type = SND_AK4358,
0273     .num_dacs = 8,  /* DAC1 - analog out
0274                DAC2 - analog in monitor
0275                DAC3 - digital out monitor
0276                DAC4 - digital in monitor
0277              */
0278     .ops = {
0279         .lock = juli_akm_lock,
0280         .unlock = juli_akm_unlock,
0281         .write = juli_akm_write,
0282         .set_rate_val = juli_akm_set_rate_val
0283     },
0284     .dac_info = juli_dac,
0285 };
0286 
0287 #define juli_mute_info      snd_ctl_boolean_mono_info
0288 
0289 static int juli_mute_get(struct snd_kcontrol *kcontrol,
0290         struct snd_ctl_elem_value *ucontrol)
0291 {
0292     struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0293     unsigned int val;
0294     val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value;
0295     if (kcontrol->private_value == GPIO_MUTE_CONTROL)
0296         /* val 0 = signal on */
0297         ucontrol->value.integer.value[0] = (val) ? 0 : 1;
0298     else
0299         /* val 1 = signal on */
0300         ucontrol->value.integer.value[0] = (val) ? 1 : 0;
0301     return 0;
0302 }
0303 
0304 static int juli_mute_put(struct snd_kcontrol *kcontrol,
0305         struct snd_ctl_elem_value *ucontrol)
0306 {
0307     struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0308     unsigned int old_gpio, new_gpio;
0309     old_gpio = ice->gpio.get_data(ice);
0310     if (ucontrol->value.integer.value[0]) {
0311         /* unmute */
0312         if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
0313             /* 0 = signal on */
0314             new_gpio = old_gpio & ~GPIO_MUTE_CONTROL;
0315             /* un-smuting DAC */
0316             snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01);
0317         } else
0318             /* 1 = signal on */
0319             new_gpio =  old_gpio |
0320                 (unsigned int) kcontrol->private_value;
0321     } else {
0322         /* mute */
0323         if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
0324             /* 1 = signal off */
0325             new_gpio = old_gpio | GPIO_MUTE_CONTROL;
0326             /* smuting DAC */
0327             snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03);
0328         } else
0329             /* 0 = signal off */
0330             new_gpio =  old_gpio &
0331                 ~((unsigned int) kcontrol->private_value);
0332     }
0333     /* dev_dbg(ice->card->dev,
0334         "JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, "
0335         "new_gpio 0x%x\n",
0336         (unsigned int)ucontrol->value.integer.value[0], old_gpio,
0337         new_gpio); */
0338     if (old_gpio != new_gpio) {
0339         ice->gpio.set_data(ice, new_gpio);
0340         return 1;
0341     }
0342     /* no change */
0343     return 0;
0344 }
0345 
0346 static const struct snd_kcontrol_new juli_mute_controls[] = {
0347     {
0348         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0349         .name = "Master Playback Switch",
0350         .info = juli_mute_info,
0351         .get = juli_mute_get,
0352         .put = juli_mute_put,
0353         .private_value = GPIO_MUTE_CONTROL,
0354     },
0355     /* Although the following functionality respects the succint NDA'd
0356      * documentation from the card manufacturer, and the same way of
0357      * operation is coded in OSS Juli driver, only Digital Out monitor
0358      * seems to work. Surprisingly, Analog input monitor outputs Digital
0359      * output data. The two are independent, as enabling both doubles
0360      * volume of the monitor sound.
0361      *
0362      * Checking traces on the board suggests the functionality described
0363      * by the manufacturer is correct - I2S from ADC and AK4114
0364      * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor
0365      * inputs) are fed from Xilinx.
0366      *
0367      * I even checked traces on board and coded a support in driver for
0368      * an alternative possibility - the unused I2S ICE output channels
0369      * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
0370      * the DAC - to no avail. The I2S outputs seem to be unconnected.
0371      *
0372      * The windows driver supports the monitoring correctly.
0373      */
0374     {
0375         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0376         .name = "Monitor Analog In Switch",
0377         .info = juli_mute_info,
0378         .get = juli_mute_get,
0379         .put = juli_mute_put,
0380         .private_value = GPIO_ANAIN_MONITOR,
0381     },
0382     {
0383         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0384         .name = "Monitor Digital Out Switch",
0385         .info = juli_mute_info,
0386         .get = juli_mute_get,
0387         .put = juli_mute_put,
0388         .private_value = GPIO_DIGOUT_MONITOR,
0389     },
0390     {
0391         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0392         .name = "Monitor Digital In Switch",
0393         .info = juli_mute_info,
0394         .get = juli_mute_get,
0395         .put = juli_mute_put,
0396         .private_value = GPIO_DIGIN_MONITOR,
0397     },
0398 };
0399 
0400 static const char * const follower_vols[] = {
0401     PCM_VOLUME,
0402     MONITOR_AN_IN_VOLUME,
0403     MONITOR_DIG_IN_VOLUME,
0404     MONITOR_DIG_OUT_VOLUME,
0405     NULL
0406 };
0407 
0408 static
0409 DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
0410 
0411 static struct snd_kcontrol *ctl_find(struct snd_card *card,
0412                      const char *name)
0413 {
0414     struct snd_ctl_elem_id sid = {0};
0415 
0416     strscpy(sid.name, name, sizeof(sid.name));
0417     sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
0418     return snd_ctl_find_id(card, &sid);
0419 }
0420 
0421 static void add_followers(struct snd_card *card,
0422               struct snd_kcontrol *master,
0423               const char * const *list)
0424 {
0425     for (; *list; list++) {
0426         struct snd_kcontrol *follower = ctl_find(card, *list);
0427         /* dev_dbg(card->dev, "add_followers - %s\n", *list); */
0428         if (follower) {
0429             /* dev_dbg(card->dev, "follower %s found\n", *list); */
0430             snd_ctl_add_follower(master, follower);
0431         }
0432     }
0433 }
0434 
0435 static int juli_add_controls(struct snd_ice1712 *ice)
0436 {
0437     struct juli_spec *spec = ice->spec;
0438     int err;
0439     unsigned int i;
0440     struct snd_kcontrol *vmaster;
0441 
0442     err = snd_ice1712_akm4xxx_build_controls(ice);
0443     if (err < 0)
0444         return err;
0445 
0446     for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) {
0447         err = snd_ctl_add(ice->card,
0448                 snd_ctl_new1(&juli_mute_controls[i], ice));
0449         if (err < 0)
0450             return err;
0451     }
0452     /* Create virtual master control */
0453     vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
0454                           juli_master_db_scale);
0455     if (!vmaster)
0456         return -ENOMEM;
0457     add_followers(ice->card, vmaster, follower_vols);
0458     err = snd_ctl_add(ice->card, vmaster);
0459     if (err < 0)
0460         return err;
0461 
0462     /* only capture SPDIF over AK4114 */
0463     return snd_ak4114_build(spec->ak4114, NULL,
0464             ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
0465 }
0466 
0467 /*
0468  * suspend/resume
0469  * */
0470 
0471 #ifdef CONFIG_PM_SLEEP
0472 static int juli_resume(struct snd_ice1712 *ice)
0473 {
0474     struct snd_akm4xxx *ak = ice->akm;
0475     struct juli_spec *spec = ice->spec;
0476     /* akm4358 un-reset, un-mute */
0477     snd_akm4xxx_reset(ak, 0);
0478     /* reinit ak4114 */
0479     snd_ak4114_resume(spec->ak4114);
0480     return 0;
0481 }
0482 
0483 static int juli_suspend(struct snd_ice1712 *ice)
0484 {
0485     struct snd_akm4xxx *ak = ice->akm;
0486     struct juli_spec *spec = ice->spec;
0487     /* akm4358 reset and soft-mute */
0488     snd_akm4xxx_reset(ak, 1);
0489     snd_ak4114_suspend(spec->ak4114);
0490     return 0;
0491 }
0492 #endif
0493 
0494 /*
0495  * initialize the chip
0496  */
0497 
0498 static inline int juli_is_spdif_master(struct snd_ice1712 *ice)
0499 {
0500     return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1;
0501 }
0502 
0503 static unsigned int juli_get_rate(struct snd_ice1712 *ice)
0504 {
0505     int i;
0506     unsigned char result;
0507 
0508     result =  ice->gpio.get_data(ice) & GPIO_RATE_MASK;
0509     for (i = 0; i < ARRAY_SIZE(gpio_vals); i++)
0510         if (gpio_vals[i] == result)
0511             return juli_rates[i];
0512     return 0;
0513 }
0514 
0515 /* setting new rate */
0516 static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
0517 {
0518     unsigned int old, new;
0519     unsigned char val;
0520 
0521     old = ice->gpio.get_data(ice);
0522     new =  (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
0523     /* dev_dbg(ice->card->dev, "JULI - set_rate: old %x, new %x\n",
0524             old & GPIO_RATE_MASK,
0525             new & GPIO_RATE_MASK); */
0526 
0527     ice->gpio.set_data(ice, new);
0528     /* switching to external clock - supplied by external circuits */
0529     val = inb(ICEMT1724(ice, RATE));
0530     outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
0531 }
0532 
0533 static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
0534                       unsigned int rate)
0535 {
0536     /* no change in master clock */
0537     return 0;
0538 }
0539 
0540 /* setting clock to external - SPDIF */
0541 static int juli_set_spdif_clock(struct snd_ice1712 *ice, int type)
0542 {
0543     unsigned int old;
0544     old = ice->gpio.get_data(ice);
0545     /* external clock (= 0), multiply 1x, 48kHz */
0546     ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
0547             GPIO_FREQ_48KHZ);
0548     return 0;
0549 }
0550 
0551 /* Called when ak4114 detects change in the input SPDIF stream */
0552 static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
0553                    unsigned char c1)
0554 {
0555     struct snd_ice1712 *ice = ak4114->change_callback_private;
0556     int rate;
0557     if (ice->is_spdif_master(ice) && c1) {
0558         /* only for SPDIF master mode, rate was changed */
0559         rate = snd_ak4114_external_rate(ak4114);
0560         /* dev_dbg(ice->card->dev, "ak4114 - input rate changed to %d\n",
0561                 rate); */
0562         juli_akm_set_rate_val(ice->akm, rate);
0563     }
0564 }
0565 
0566 static int juli_init(struct snd_ice1712 *ice)
0567 {
0568     static const unsigned char ak4114_init_vals[] = {
0569         /* AK4117_REG_PWRDN */  AK4114_RST | AK4114_PWN |
0570                     AK4114_OCKS0 | AK4114_OCKS1,
0571         /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S,
0572         /* AK4114_REG_IO0 */    AK4114_TX1E,
0573         /* AK4114_REG_IO1 */    AK4114_EFH_1024 | AK4114_DIT |
0574                     AK4114_IPS(1),
0575         /* AK4114_REG_INT0_MASK */ 0,
0576         /* AK4114_REG_INT1_MASK */ 0
0577     };
0578     static const unsigned char ak4114_init_txcsb[] = {
0579         0x41, 0x02, 0x2c, 0x00, 0x00
0580     };
0581     int err;
0582     struct juli_spec *spec;
0583     struct snd_akm4xxx *ak;
0584 
0585     spec = kzalloc(sizeof(*spec), GFP_KERNEL);
0586     if (!spec)
0587         return -ENOMEM;
0588     ice->spec = spec;
0589 
0590     err = snd_ak4114_create(ice->card,
0591                 juli_ak4114_read,
0592                 juli_ak4114_write,
0593                 ak4114_init_vals, ak4114_init_txcsb,
0594                 ice, &spec->ak4114);
0595     if (err < 0)
0596         return err;
0597     /* callback for codecs rate setting */
0598     spec->ak4114->change_callback = juli_ak4114_change;
0599     spec->ak4114->change_callback_private = ice;
0600     /* AK4114 in Juli can detect external rate correctly */
0601     spec->ak4114->check_flags = 0;
0602 
0603 #if 0
0604 /*
0605  * it seems that the analog doughter board detection does not work reliably, so
0606  * force the analog flag; it should be very rare (if ever) to come at Juli@
0607  * used without the analog daughter board
0608  */
0609     spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1;
0610 #else
0611     spec->analog = 1;
0612 #endif
0613 
0614     if (spec->analog) {
0615         dev_info(ice->card->dev, "juli@: analog I/O detected\n");
0616         ice->num_total_dacs = 2;
0617         ice->num_total_adcs = 2;
0618 
0619         ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
0620         ak = ice->akm;
0621         if (!ak)
0622             return -ENOMEM;
0623         ice->akm_codecs = 1;
0624         err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice);
0625         if (err < 0)
0626             return err;
0627     }
0628 
0629     /* juli is clocked by Xilinx array */
0630     ice->hw_rates = &juli_rates_info;
0631     ice->is_spdif_master = juli_is_spdif_master;
0632     ice->get_rate = juli_get_rate;
0633     ice->set_rate = juli_set_rate;
0634     ice->set_mclk = juli_set_mclk;
0635     ice->set_spdif_clock = juli_set_spdif_clock;
0636 
0637     ice->spdif.ops.open = juli_spdif_in_open;
0638 
0639 #ifdef CONFIG_PM_SLEEP
0640     ice->pm_resume = juli_resume;
0641     ice->pm_suspend = juli_suspend;
0642     ice->pm_suspend_enabled = 1;
0643 #endif
0644 
0645     return 0;
0646 }
0647 
0648 
0649 /*
0650  * Juli@ boards don't provide the EEPROM data except for the vendor IDs.
0651  * hence the driver needs to sets up it properly.
0652  */
0653 
0654 static const unsigned char juli_eeprom[] = {
0655     [ICE_EEP2_SYSCONF]     = 0x2b,  /* clock 512, mpu401, 1xADC, 1xDACs,
0656                        SPDIF in */
0657     [ICE_EEP2_ACLINK]      = 0x80,  /* I2S */
0658     [ICE_EEP2_I2S]         = 0xf8,  /* vol, 96k, 24bit, 192k */
0659     [ICE_EEP2_SPDIF]       = 0xc3,  /* out-en, out-int, spdif-in */
0660     [ICE_EEP2_GPIO_DIR]    = 0x9f,  /* 5, 6:inputs; 7, 4-0 outputs*/
0661     [ICE_EEP2_GPIO_DIR1]   = 0xff,
0662     [ICE_EEP2_GPIO_DIR2]   = 0x7f,
0663     [ICE_EEP2_GPIO_MASK]   = 0x60,  /* 5, 6: locked; 7, 4-0 writable */
0664     [ICE_EEP2_GPIO_MASK1]  = 0x00,  /* 0-7 writable */
0665     [ICE_EEP2_GPIO_MASK2]  = 0x7f,
0666     [ICE_EEP2_GPIO_STATE]  = GPIO_FREQ_48KHZ | GPIO_MULTI_1X |
0667            GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/
0668     [ICE_EEP2_GPIO_STATE1] = 0x00,  /* unmuted */
0669     [ICE_EEP2_GPIO_STATE2] = 0x00,
0670 };
0671 
0672 /* entry point */
0673 struct snd_ice1712_card_info snd_vt1724_juli_cards[] = {
0674     {
0675         .subvendor = VT1724_SUBDEVICE_JULI,
0676         .name = "ESI Juli@",
0677         .model = "juli",
0678         .chip_init = juli_init,
0679         .build_controls = juli_add_controls,
0680         .eeprom_size = sizeof(juli_eeprom),
0681         .eeprom_data = juli_eeprom,
0682     },
0683     { } /* terminator */
0684 };