This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/TAS5751M: we want the TAS5751 software development support

Part Number: TAS5751M
Other Parts Discussed in Thread: TAS5782M

Tool/software: Linux

Would you please share us the Linux drive or  programming guide of TAS5751?

  • Hi Billy,

    Unfortunately we don't have the Linux driver for TAS5751M. You could generate the register configuration head file by TAS5751M EVM and PPC3 GUI. Please find more detailed info in the TAS5751M EVM user's guide:

    Then you could write the driver with it. Here is an example for another product TAS5782M, hope it helps you.

    tas5782m.c
    /*
     * Driver for the TAS5782M Audio Amplifier
     *
     * Author: Andy Liu <andy-liu@ti.com>
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     * This program is distributed in the hope that it will be useful, but
     * WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * General Public License for more details.
     */
    
    #include <linux/module.h>
    #include <linux/moduleparam.h>
    #include <linux/slab.h>
    #include <linux/of.h>
    #include <linux/init.h>
    #include <linux/i2c.h>
    #include <linux/regmap.h>
    
    #include <sound/soc.h>
    #include <sound/pcm.h>
    #include <sound/initval.h>
    
    #include "ppc3_tuning_-30dB.h"
    
    #define TAS5872M_DRV_NAME    "tas5782m"
    
    #define TAS5872M_RATES	     (SNDRV_PCM_RATE_48000)
    #define TAS5782M_FORMATS     (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
    			                  SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
    
    #define TAS5782M_REG_00      (0x00)
    #define TAS5782M_REG_03      (0x03)
    #define TAS5782M_REG_7F      (0x7F)
    #define TAS5782M_REG_14      (0x14)
    #define TAS5782M_REG_15      (0x15)
    #define TAS5782M_REG_16      (0x16)
    #define TAS5782M_REG_17      (0x17)
    
    #define TAS5782M_REG_44      (0x44)
    #define TAS5782M_REG_45      (0x45)
    #define TAS5782M_REG_46      (0x46)
    #define TAS5782M_REG_47      (0x47)
    #define TAS5782M_REG_48      (0x48)
    #define TAS5782M_REG_49      (0x49)
    #define TAS5782M_REG_4A      (0x4A)
    #define TAS5782M_REG_4B      (0x4B)
    
    #define TAS5782M_PAGE_00     (0x00)
    #define TAS5782M_PAGE_8C     (0x8C)     
    #define TAS5782M_PAGE_1E     (0x1E)
    #define TAS5782M_PAGE_23     (0x23)
    
    const uint32_t tas5782m_volume[] = {
    	0x07ECA9CD,    //24dB
    	0x07100C4D,    //23dB
    	0x064B6CAE,    //22dB
    	0x059C2F02,    //21dB
    	0x05000000,    //20dB
    	0x0474CD1B,    //19dB
    	0x03F8BD7A,    //18dB
    	0x038A2BAD,    //17dB
    	0x0327A01A,    //16dB
    	0x02CFCC01,    //15dB
    	0x02818508,    //14dB
    	0x023BC148,    //13dB
    	0x01FD93C2,    //12dB
    	0x01C62940,    //11dB
    	0x0194C584,    //10dB
    	0x0168C0C6,    //9dB
    	0x0141857F,    //8dB
    	0x011E8E6A,    //7dB
    	0x00FF64C1,    //6dB
    	0x00E39EA9,    //5dB
    	0x00CADDC8,    //4dB
    	0x00B4CE08,    //3dB
    	0x00A12478,    //2dB
    	0x008F9E4D,    //1dB
    	0x00800000,    //0dB
    	0x00721483,    //-1dB
    	0x0065AC8C,    //-2dB
    	0x005A9DF8,    //-3dB
    	0x0050C336,    //-4dB
    	0x0047FACD,    //-5dB
    	0x004026E7,    //-6dB
    	0x00392CEE,    //-7dB
    	0x0032F52D,    //-8dB
    	0x002D6A86,    //-9dB
    	0x00287A27,    //-10dB
    	0x00241347,    //-11dB
    	0x002026F3,    //-12dB
    	0x001CA7D7,    //-13dB
    	0x00198A13,    //-14dB
    	0x0016C311,    //-15dB
    	0x00144961,    //-16dB
    	0x0012149A,    //-17dB
    	0x00101D3F,    //-18dB
    	0x000E5CA1,    //-19dB
    	0x000CCCCD,    //-20dB
    	0x000B6873,    //-21dB
    	0x000A2ADB,    //-22dB
    	0x00090FCC,    //-23dB
    	0x00081385,    //-24dB
    	0x000732AE,    //-25dB
    	0x00066A4A,    //-26dB
    	0x0005B7B1,    //-27dB
    	0x00051884,    //-28dB
    	0x00048AA7,    //-29dB
    	0x00040C37,    //-30dB
    	0x00039B87,    //-31dB
    	0x00033718,    //-32dB
    	0x0002DD96,    //-33dB
    	0x00028DCF,    //-34dB
    	0x000246B5,    //-35dB
    	0x00020756,    //-36dB
    	0x0001CEDC,    //-37dB
    	0x00019C86,    //-38dB
    	0x00016FAA,    //-39dB
    	0x000147AE,    //-40dB
    	0x0001240C,    //-41dB
    	0x00010449,    //-42dB
    	0x0000E7FB,    //-43dB
    	0x0000CEC1,    //-44dB
    	0x0000B845,    //-45dB
    	0x0000A43B,    //-46dB
    	0x0000925F,    //-47dB
    	0x00008274,    //-48dB
    	0x00007444,    //-49dB
    	0x0000679F,    //-50dB
    	0x00005C5A,    //-51dB
    	0x0000524F,    //-52dB
    	0x0000495C,    //-53dB
    	0x00004161,    //-54dB
    	0x00003A45,    //-55dB
    	0x000033EF,    //-56dB
    	0x00002E49,    //-57dB
    	0x00002941,    //-58dB
    	0x000024C4,    //-59dB
    	0x000020C5,    //-60dB
    	0x00001D34,    //-61dB
    	0x00001A07,    //-62dB
    	0x00001733,    //-63dB
    	0x000014AD,    //-64dB
    	0x0000126D,    //-65dB
    	0x0000106C,    //-66dB
    	0x00000EA3,    //-67dB
    	0x00000D0C,    //-68dB
    	0x00000BA0,    //-69dB
    	0x00000A5D,    //-70dB
    	0x0000093C,    //-71dB
    	0x0000083B,    //-72dB
    	0x00000756,    //-73dB
    	0x0000068A,    //-74dB
    	0x000005D4,    //-75dB
    	0x00000532,    //-76dB
    	0x000004A1,    //-77dB
    	0x00000420,    //-78dB
    	0x000003AD,    //-79dB
    	0x00000347,    //-80dB
    	0x000002EC,    //-81dB
    	0x0000029A,    //-82dB
    	0x00000252,    //-83dB
    	0x00000211,    //-84dB
    	0x000001D8,    //-85dB
    	0x000001A4,    //-86dB
    	0x00000177,    //-87dB
    	0x0000014E,    //-88dB
    	0x0000012A,    //-89dB
    	0x00000109,    //-90dB
    	0x000000EC,    //-91dB
    	0x000000D3,    //-92dB
    	0x000000BC,    //-93dB
    	0x000000A7,    //-94dB
    	0x00000095,    //-95dB
    	0x00000085,    //-96dB
    	0x00000076,    //-97dB
    	0x0000006A,    //-98dB
    	0x0000005E,    //-99dB
    	0x00000054,    //-100dB
    	0x0000004B,    //-101dB
    	0x00000043,    //-102dB
    	0x0000003B,    //-103dB
    	0x00000035,    //-104dB
    	0x0000002F,    //-105dB
    	0x0000002A,    //-106dB
    	0x00000025,    //-107dB
    	0x00000021,    //-108dB
    	0x0000001E,    //-109dB
    	0x0000001B,    //-110dB
    };
    
    struct tas5782m_priv {
    	struct regmap *regmap;
    
    	int volume_db;
    };
    
    const struct regmap_config tas5782m_regmap = {
    	.reg_bits = 8,
    	.val_bits = 8,
    	.cache_type = REGCACHE_RBTREE,
    };
    
    static int tas5782m_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
    {
    	uinfo->type   = SNDRV_CTL_ELEM_TYPE_INTEGER;
    	uinfo->access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE;
    	uinfo->count  = 1;
    	
    	uinfo->value.integer.min  = -110;
    	uinfo->value.integer.max  = 24;
    	uinfo->value.integer.step = 1;
    
    	return 0;
    }
    
    static inline int get_db(int index)
    {
       //input  : 0  -- 134
       //output : 24 -- -110
    
       return (24 - index);
    }
    
    static int tas5782m_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    {
    	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
    	struct tas5782m_priv *tas5782m = snd_soc_codec_get_drvdata(codec);
    			
    	ucontrol->value.integer.value[0] = tas5782m->volume_db;
    
    	return 0;
    }
    
    static inline unsigned int get_volume_index(int vol)
    {
       //input  : 24 -- -110
       //output : 0  -- 134
       return (24 - vol);
    }
    
    static void tas5782m_set_volume(struct snd_soc_codec *codec, int db)
    {
        unsigned int index;
    	uint32_t volume_hex;
    	uint8_t byte4;
    	uint8_t byte3;
    	uint8_t byte2;
    	uint8_t byte1;
     
    	index = get_volume_index(db);
    	volume_hex = tas5782m_volume[index];
    
    	byte4 = ((volume_hex >> 24) & 0xFF);
    	byte3 = ((volume_hex >> 16) & 0xFF);
    	byte2 = ((volume_hex >> 8)	& 0xFF);
    	byte1 = ((volume_hex >> 0)	& 0xFF);
    #if 1	
    	//w 90 00 00
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_00);
    	//w 90 7f 8c
    	snd_soc_write(codec, TAS5782M_REG_7F, TAS5782M_PAGE_8C);
    	//w 90 00 1e
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_1E);
    	//w 90 44 xx xx xx xx 
    	snd_soc_write(codec, TAS5782M_REG_44, byte4);
    	snd_soc_write(codec, TAS5782M_REG_45, byte3);
    	snd_soc_write(codec, TAS5782M_REG_46, byte2);
    	snd_soc_write(codec, TAS5782M_REG_47, byte1);
    	
    	//w 90 00 00
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_00);
    	//w 90 7f 8c
    	snd_soc_write(codec, TAS5782M_REG_7F, TAS5782M_PAGE_8C);	
    	//w 90 00 1e
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_1E);	
    	//w 90 48 xx xx xx xx 
    	snd_soc_write(codec, TAS5782M_REG_48, byte4);
    	snd_soc_write(codec, TAS5782M_REG_49, byte3);
    	snd_soc_write(codec, TAS5782M_REG_4A, byte2);
    	snd_soc_write(codec, TAS5782M_REG_4B, byte1);
    	
    	//w 90 00 00
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_00);	
    	//w 90 7f 8c
    	snd_soc_write(codec, TAS5782M_REG_7F, TAS5782M_PAGE_8C);	
    	//w 90 00 23
    	snd_soc_write(codec, TAS5782M_REG_00, TAS5782M_PAGE_23);	
    	//w 90 14 00 00 00 01 
    	snd_soc_write(codec, TAS5782M_REG_14, 0x00);
    	snd_soc_write(codec, TAS5782M_REG_15, 0x00);
    	snd_soc_write(codec, TAS5782M_REG_16, 0x00);
    	snd_soc_write(codec, TAS5782M_REG_17, 0x01);
    #endif
    }
    
    static int tas5782m_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
    {
    	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
    	struct tas5782m_priv *tas5782m = snd_soc_codec_get_drvdata(codec);
    		
    	int db;
    	
    	db = ucontrol->value.integer.value[0];
    	tas5782m->volume_db = db;
    	tas5782m_set_volume(codec, db);
    
    	return 0;
    }
    
    static const struct snd_kcontrol_new tas5782m_vol_control = 
    {	
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 
        .name  = "TAS5782M Software Volume", 
    	.info  = tas5782m_vol_info, 
    	.get   = tas5782m_vol_get,
    	.put   = tas5782m_vol_put, 
    };
    
    static int tas5782m_snd_probe(struct snd_soc_codec *codec)
    {
        int ret;
    		
    	ret = snd_soc_add_codec_controls(codec, &tas5782m_vol_control, 1);
    		
        return ret;
    }
    
    static struct snd_soc_codec_driver soc_codec_tas5782m = {
    	.probe = tas5782m_snd_probe,
    };
    
    static int tas5782m_mute(struct snd_soc_dai *dai, int mute)
    {
    	u8 reg3_value = 0;
    	struct snd_soc_codec *codec = dai->codec;
    	
    	if (mute)
    		reg3_value = 0x11;
    	
    	snd_soc_write(codec, TAS5782M_REG_00, 0x00);
    	snd_soc_write(codec, TAS5782M_REG_7F, 0x00);
    	snd_soc_write(codec, TAS5782M_REG_03, reg3_value);
    
    	return 0;
    }
    
    static const struct snd_soc_dai_ops tas5782m_dai_ops = {
    	.digital_mute = tas5782m_mute,
    };
    
    static struct snd_soc_dai_driver tas5782m_dai = {
    	.name		= "tas5782m-amplifier",
    	.playback 	= {
    		.stream_name	= "Playback",
    		.channels_min	= 2,
    		.channels_max	= 2,
    		.rates		= TAS5872M_RATES,
    		.formats	= TAS5782M_FORMATS,
    	},
    	.ops = &tas5782m_dai_ops,
    };
    
    static int tas5782m_probe(struct device *dev, struct regmap *regmap)
    {
    	struct tas5782m_priv *tas5782m;
    	int ret;
    		
    	tas5782m = devm_kzalloc(dev, sizeof(struct tas5782m_priv), GFP_KERNEL);
    	if (!tas5782m)
    		return -ENOMEM;
    
    	dev_set_drvdata(dev, tas5782m);
    	tas5782m->regmap = regmap;
        tas5782m->volume_db = -30;
    	
    	ret = regmap_register_patch(regmap, tas5782m_init_sequence, ARRAY_SIZE(tas5782m_init_sequence));
    	if (ret != 0)
    	{
    		dev_err(dev, "Failed to initialize TAS5782M: %d\n",ret);
    		goto err;
    
    	}
    
    	ret = snd_soc_register_codec(dev, 
    	                             &soc_codec_tas5782m,
    			                     &tas5782m_dai, 
    								 1);
    	if (ret != 0) 
    	{
    		dev_err(dev, "Failed to register CODEC: %d\n", ret);
    		goto err;
    	}
    
    	return 0;
    	
    err:
    	return ret;
    
    }
    
    static int tas5782m_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
    {	
    	struct regmap *regmap;
    	struct regmap_config config = tas5782m_regmap;
    	
    	regmap = devm_regmap_init_i2c(i2c, &config);
    	if (IS_ERR(regmap))
    		return PTR_ERR(regmap);
    
    	return tas5782m_probe(&i2c->dev, regmap);
    }
    
    static int tas5782m_remove(struct device *dev)
    {	
    	snd_soc_unregister_codec(dev);
    	
    	return 0;
    }
    
    static int tas5782m_i2c_remove(struct i2c_client *i2c)
    {	
    	tas5782m_remove(&i2c->dev);
    	
    	return 0;
    }
    
    static const struct i2c_device_id tas5782m_i2c_id[] = {
    	{ "tas5782m", },
    	{ }
    };
    MODULE_DEVICE_TABLE(i2c, tas5782m_i2c_id);
    
    #ifdef CONFIG_OF
    static const struct of_device_id tas5782m_of_match[] = {
    	{ .compatible = "ti,tas5782m", },
    	{ }
    };
    MODULE_DEVICE_TABLE(of, tas5782m_of_match);
    #endif
    
    static struct i2c_driver tas5782m_i2c_driver = {
    	.probe 		= tas5782m_i2c_probe,
    	.remove 	= tas5782m_i2c_remove,
    	.id_table	= tas5782m_i2c_id,
    	.driver		= {
    		.name	= TAS5872M_DRV_NAME,
    		.of_match_table = tas5782m_of_match,
    	},
    };
    
    module_i2c_driver(tas5782m_i2c_driver);
    
    MODULE_AUTHOR("Andy Liu <andy-liu@ti.com>");
    MODULE_DESCRIPTION("TAS5782M Audio Amplifier Driver");
    MODULE_LICENSE("GPL");
    

    Best regards,

    Shawn Zheng