@@ -113,8 +113,6 @@ struct es8316_chip {
113113 int pwr_count ;
114114};
115115
116- struct es8316_chip * es8316_private ;
117-
118116/*
119117 * es8316_reset
120118 * write value 0xff to reg0x00, the chip will be in reset mode
@@ -127,10 +125,8 @@ static int es8316_reset(struct snd_soc_codec *codec)
127125 return snd_soc_write (codec , ES8316_RESET_REG00 , 0x03 );
128126}
129127
130- static int es8316_set_gpio (int gpio , bool level )
128+ static int es8316_set_gpio (struct es8316_chip * chip , int gpio , bool level )
131129{
132- struct es8316_chip * chip = es8316_private ;
133-
134130 if (!chip ) {
135131 DBG ("%s : es8316_chip is NULL\n" , __func__ );
136132 return 0 ;
@@ -153,7 +149,7 @@ static irqreturn_t hp_det_irq_handler(int irq, void *dev_id)
153149{
154150 int ret ;
155151 unsigned int type ;
156- struct es8316_chip * chip = es8316_private ;
152+ struct es8316_chip * chip = ( struct es8316_chip * ) dev_id ;
157153
158154 disable_irq_nosync (irq );
159155
@@ -173,12 +169,12 @@ static irqreturn_t hp_det_irq_handler(int irq, void *dev_id)
173169 if (mute_flag == 0 ) {
174170 if (chip -> hp_det_level == gpio_get_value (chip -> hp_det_gpio ))
175171 {
176- es8316_set_gpio (ES8316_CODEC_SET_SPK , !chip -> spk_gpio_level );
172+ es8316_set_gpio (chip , ES8316_CODEC_SET_SPK , !chip -> spk_gpio_level );
177173 printk ("%s, %d, %d\n" , __FUNCTION__ , __LINE__ , !chip -> spk_gpio_level );
178174 }
179175 else
180176 {
181- es8316_set_gpio (ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
177+ es8316_set_gpio (chip , ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
182178 printk ("%s, %d, %d\n" , __FUNCTION__ , __LINE__ , chip -> spk_gpio_level );
183179 }
184180 }
@@ -955,12 +951,13 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
955951
956952static int es8316_mute (struct snd_soc_dai * dai , int mute )
957953{
954+ /* 根据DAI来获取chip */
958955 struct snd_soc_codec * codec = dai -> codec ;
959- struct es8316_chip * chip = es8316_private ;
956+ struct es8316_chip * chip = snd_soc_codec_get_drvdata ( codec ) ;
960957
961958 mute_flag = mute ;
962959 if (mute ) {
963- es8316_set_gpio (ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
960+ es8316_set_gpio (chip , ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
964961 printk ("%s, %d, %d\n" , __FUNCTION__ , __LINE__ , !chip -> spk_gpio_level );
965962 msleep (100 );
966963 snd_soc_write (codec , ES8316_DAC_SET1_REG30 , 0x20 );
@@ -969,7 +966,7 @@ static int es8316_mute(struct snd_soc_dai *dai, int mute)
969966 msleep (130 );
970967 if (hp_irq_flag == 0 )
971968 {
972- es8316_set_gpio (ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
969+ es8316_set_gpio (chip , ES8316_CODEC_SET_SPK , chip -> spk_gpio_level );
973970 printk ("%s, %d, %d\n" , __FUNCTION__ , __LINE__ , chip -> spk_gpio_level );
974971 }
975972 msleep (150 );
@@ -1245,15 +1242,15 @@ static struct snd_soc_codec_driver soc_codec_dev_es8316 = {
12451242
12461243#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE )
12471244
1248- static void es8316_i2c_shutdown (struct i2c_client * i2c )
1245+ static void es8316_i2c_shutdown (struct i2c_client * client )
12491246{
12501247 struct snd_soc_codec * codec ;
1251- struct es8316_chip * chip = es8316_private ;
1248+ struct es8316_chip * chip = container_of ( client , struct es8316_chip , client ) ;
12521249
12531250 if (!es8316_codec )
12541251 goto err ;
12551252
1256- es8316_set_gpio (ES8316_CODEC_SET_SPK , !chip -> spk_gpio_level );
1253+ es8316_set_gpio (chip , ES8316_CODEC_SET_SPK , !chip -> spk_gpio_level );
12571254 printk ("%s, %d, %d\n" , __FUNCTION__ , __LINE__ , !chip -> spk_gpio_level );
12581255 mdelay (150 );
12591256
@@ -1353,8 +1350,6 @@ static int es8316_i2c_probe(struct i2c_client *client,
13531350 printk ("ERROR: No memory\n" );
13541351 return - ENOMEM ;
13551352 }
1356- else
1357- es8316_private = chip ;
13581353
13591354 /* 设置chip */
13601355 chip -> client = client ;
0 commit comments