.. | .. |
---|
19 | 19 | #include "fsl_asrc.h" |
---|
20 | 20 | |
---|
21 | 21 | #define IDEAL_RATIO_DECIMAL_DEPTH 26 |
---|
| 22 | +#define DIVIDER_NUM 64 |
---|
22 | 23 | |
---|
23 | 24 | #define pair_err(fmt, ...) \ |
---|
24 | | - dev_err(&asrc_priv->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__) |
---|
| 25 | + dev_err(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__) |
---|
25 | 26 | |
---|
26 | 27 | #define pair_dbg(fmt, ...) \ |
---|
27 | | - dev_dbg(&asrc_priv->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__) |
---|
28 | | - |
---|
29 | | -/* Sample rates are aligned with that defined in pcm.h file */ |
---|
30 | | -static const u8 process_option[][12][2] = { |
---|
31 | | - /* 8kHz 11.025kHz 16kHz 22.05kHz 32kHz 44.1kHz 48kHz 64kHz 88.2kHz 96kHz 176kHz 192kHz */ |
---|
32 | | - {{0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},}, /* 5512Hz */ |
---|
33 | | - {{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},}, /* 8kHz */ |
---|
34 | | - {{0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},}, /* 11025Hz */ |
---|
35 | | - {{1, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},}, /* 16kHz */ |
---|
36 | | - {{1, 2}, {1, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},}, /* 22050Hz */ |
---|
37 | | - {{1, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0},}, /* 32kHz */ |
---|
38 | | - {{2, 2}, {2, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0},}, /* 44.1kHz */ |
---|
39 | | - {{2, 2}, {2, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0},}, /* 48kHz */ |
---|
40 | | - {{2, 2}, {2, 2}, {2, 2}, {2, 1}, {1, 2}, {0, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0},}, /* 64kHz */ |
---|
41 | | - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1},}, /* 88.2kHz */ |
---|
42 | | - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1},}, /* 96kHz */ |
---|
43 | | - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1},}, /* 176kHz */ |
---|
44 | | - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, {2, 1},}, /* 192kHz */ |
---|
45 | | -}; |
---|
| 28 | + dev_dbg(&asrc->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS__) |
---|
46 | 29 | |
---|
47 | 30 | /* Corresponding to process_option */ |
---|
48 | | -static int supported_input_rate[] = { |
---|
49 | | - 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, |
---|
50 | | - 96000, 176400, 192000, |
---|
| 31 | +static unsigned int supported_asrc_rate[] = { |
---|
| 32 | + 5512, 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, |
---|
| 33 | + 64000, 88200, 96000, 128000, 176400, 192000, |
---|
51 | 34 | }; |
---|
52 | 35 | |
---|
53 | | -static int supported_asrc_rate[] = { |
---|
54 | | - 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000, |
---|
| 36 | +static struct snd_pcm_hw_constraint_list fsl_asrc_rate_constraints = { |
---|
| 37 | + .count = ARRAY_SIZE(supported_asrc_rate), |
---|
| 38 | + .list = supported_asrc_rate, |
---|
55 | 39 | }; |
---|
56 | 40 | |
---|
57 | | -/** |
---|
| 41 | +/* |
---|
58 | 42 | * The following tables map the relationship between asrc_inclk/asrc_outclk in |
---|
59 | 43 | * fsl_asrc.h and the registers of ASRCSR |
---|
60 | 44 | */ |
---|
61 | | -static unsigned char input_clk_map_imx35[] = { |
---|
| 45 | +static unsigned char input_clk_map_imx35[ASRC_CLK_MAP_LEN] = { |
---|
62 | 46 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, |
---|
| 47 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
---|
| 48 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
---|
63 | 49 | }; |
---|
64 | 50 | |
---|
65 | | -static unsigned char output_clk_map_imx35[] = { |
---|
| 51 | +static unsigned char output_clk_map_imx35[ASRC_CLK_MAP_LEN] = { |
---|
66 | 52 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, |
---|
| 53 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
---|
| 54 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
---|
67 | 55 | }; |
---|
68 | 56 | |
---|
69 | 57 | /* i.MX53 uses the same map for input and output */ |
---|
70 | | -static unsigned char input_clk_map_imx53[] = { |
---|
| 58 | +static unsigned char input_clk_map_imx53[ASRC_CLK_MAP_LEN] = { |
---|
71 | 59 | /* 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf */ |
---|
72 | 60 | 0x0, 0x1, 0x2, 0x7, 0x4, 0x5, 0x6, 0x3, 0x8, 0x9, 0xa, 0xb, 0xc, 0xf, 0xe, 0xd, |
---|
| 61 | + 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, |
---|
| 62 | + 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, |
---|
73 | 63 | }; |
---|
74 | 64 | |
---|
75 | | -static unsigned char output_clk_map_imx53[] = { |
---|
| 65 | +static unsigned char output_clk_map_imx53[ASRC_CLK_MAP_LEN] = { |
---|
76 | 66 | /* 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf */ |
---|
77 | 67 | 0x8, 0x9, 0xa, 0x7, 0xc, 0x5, 0x6, 0xb, 0x0, 0x1, 0x2, 0x3, 0x4, 0xf, 0xe, 0xd, |
---|
| 68 | + 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, |
---|
| 69 | + 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, |
---|
78 | 70 | }; |
---|
79 | 71 | |
---|
80 | | -static unsigned char *clk_map[2]; |
---|
| 72 | +/* |
---|
| 73 | + * i.MX8QM/i.MX8QXP uses the same map for input and output. |
---|
| 74 | + * clk_map_imx8qm[0] is for i.MX8QM asrc0 |
---|
| 75 | + * clk_map_imx8qm[1] is for i.MX8QM asrc1 |
---|
| 76 | + * clk_map_imx8qxp[0] is for i.MX8QXP asrc0 |
---|
| 77 | + * clk_map_imx8qxp[1] is for i.MX8QXP asrc1 |
---|
| 78 | + */ |
---|
| 79 | +static unsigned char clk_map_imx8qm[2][ASRC_CLK_MAP_LEN] = { |
---|
| 80 | + { |
---|
| 81 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, |
---|
| 82 | + 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, |
---|
| 83 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 84 | + }, |
---|
| 85 | + { |
---|
| 86 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, |
---|
| 87 | + 0x0, 0x1, 0x2, 0x3, 0xb, 0xc, 0xf, 0xf, 0xd, 0xe, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 88 | + 0x4, 0x5, 0x6, 0xf, 0x8, 0x9, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 89 | + }, |
---|
| 90 | +}; |
---|
| 91 | + |
---|
| 92 | +static unsigned char clk_map_imx8qxp[2][ASRC_CLK_MAP_LEN] = { |
---|
| 93 | + { |
---|
| 94 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, |
---|
| 95 | + 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xf, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xf, 0xf, |
---|
| 96 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 97 | + }, |
---|
| 98 | + { |
---|
| 99 | + 0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, |
---|
| 100 | + 0x0, 0x1, 0x2, 0x3, 0x7, 0x8, 0xf, 0xf, 0x9, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 101 | + 0xf, 0xf, 0x6, 0xf, 0xf, 0xf, 0xa, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, |
---|
| 102 | + }, |
---|
| 103 | +}; |
---|
| 104 | + |
---|
| 105 | +/* |
---|
| 106 | + * According to RM, the divider range is 1 ~ 8, |
---|
| 107 | + * prescaler is power of 2 from 1 ~ 128. |
---|
| 108 | + */ |
---|
| 109 | +static int asrc_clk_divider[DIVIDER_NUM] = { |
---|
| 110 | + 1, 2, 4, 8, 16, 32, 64, 128, /* divider = 1 */ |
---|
| 111 | + 2, 4, 8, 16, 32, 64, 128, 256, /* divider = 2 */ |
---|
| 112 | + 3, 6, 12, 24, 48, 96, 192, 384, /* divider = 3 */ |
---|
| 113 | + 4, 8, 16, 32, 64, 128, 256, 512, /* divider = 4 */ |
---|
| 114 | + 5, 10, 20, 40, 80, 160, 320, 640, /* divider = 5 */ |
---|
| 115 | + 6, 12, 24, 48, 96, 192, 384, 768, /* divider = 6 */ |
---|
| 116 | + 7, 14, 28, 56, 112, 224, 448, 896, /* divider = 7 */ |
---|
| 117 | + 8, 16, 32, 64, 128, 256, 512, 1024, /* divider = 8 */ |
---|
| 118 | +}; |
---|
| 119 | + |
---|
| 120 | +/* |
---|
| 121 | + * Check if the divider is available for internal ratio mode |
---|
| 122 | + */ |
---|
| 123 | +static bool fsl_asrc_divider_avail(int clk_rate, int rate, int *div) |
---|
| 124 | +{ |
---|
| 125 | + u32 rem, i; |
---|
| 126 | + u64 n; |
---|
| 127 | + |
---|
| 128 | + if (div) |
---|
| 129 | + *div = 0; |
---|
| 130 | + |
---|
| 131 | + if (clk_rate == 0 || rate == 0) |
---|
| 132 | + return false; |
---|
| 133 | + |
---|
| 134 | + n = clk_rate; |
---|
| 135 | + rem = do_div(n, rate); |
---|
| 136 | + |
---|
| 137 | + if (div) |
---|
| 138 | + *div = n; |
---|
| 139 | + |
---|
| 140 | + if (rem != 0) |
---|
| 141 | + return false; |
---|
| 142 | + |
---|
| 143 | + for (i = 0; i < DIVIDER_NUM; i++) { |
---|
| 144 | + if (n == asrc_clk_divider[i]) |
---|
| 145 | + break; |
---|
| 146 | + } |
---|
| 147 | + |
---|
| 148 | + if (i == DIVIDER_NUM) |
---|
| 149 | + return false; |
---|
| 150 | + |
---|
| 151 | + return true; |
---|
| 152 | +} |
---|
81 | 153 | |
---|
82 | 154 | /** |
---|
83 | | - * Request ASRC pair |
---|
| 155 | + * fsl_asrc_sel_proc - Select the pre-processing and post-processing options |
---|
| 156 | + * @inrate: input sample rate |
---|
| 157 | + * @outrate: output sample rate |
---|
| 158 | + * @pre_proc: return value for pre-processing option |
---|
| 159 | + * @post_proc: return value for post-processing option |
---|
| 160 | + * |
---|
| 161 | + * Make sure to exclude following unsupported cases before |
---|
| 162 | + * calling this function: |
---|
| 163 | + * 1) inrate > 8.125 * outrate |
---|
| 164 | + * 2) inrate > 16.125 * outrate |
---|
| 165 | + * |
---|
| 166 | + */ |
---|
| 167 | +static void fsl_asrc_sel_proc(int inrate, int outrate, |
---|
| 168 | + int *pre_proc, int *post_proc) |
---|
| 169 | +{ |
---|
| 170 | + bool post_proc_cond2; |
---|
| 171 | + bool post_proc_cond0; |
---|
| 172 | + |
---|
| 173 | + /* select pre_proc between [0, 2] */ |
---|
| 174 | + if (inrate * 8 > 33 * outrate) |
---|
| 175 | + *pre_proc = 2; |
---|
| 176 | + else if (inrate * 8 > 15 * outrate) { |
---|
| 177 | + if (inrate > 152000) |
---|
| 178 | + *pre_proc = 2; |
---|
| 179 | + else |
---|
| 180 | + *pre_proc = 1; |
---|
| 181 | + } else if (inrate < 76000) |
---|
| 182 | + *pre_proc = 0; |
---|
| 183 | + else if (inrate > 152000) |
---|
| 184 | + *pre_proc = 2; |
---|
| 185 | + else |
---|
| 186 | + *pre_proc = 1; |
---|
| 187 | + |
---|
| 188 | + /* Condition for selection of post-processing */ |
---|
| 189 | + post_proc_cond2 = (inrate * 15 > outrate * 16 && outrate < 56000) || |
---|
| 190 | + (inrate > 56000 && outrate < 56000); |
---|
| 191 | + post_proc_cond0 = inrate * 23 < outrate * 8; |
---|
| 192 | + |
---|
| 193 | + if (post_proc_cond2) |
---|
| 194 | + *post_proc = 2; |
---|
| 195 | + else if (post_proc_cond0) |
---|
| 196 | + *post_proc = 0; |
---|
| 197 | + else |
---|
| 198 | + *post_proc = 1; |
---|
| 199 | +} |
---|
| 200 | + |
---|
| 201 | +/** |
---|
| 202 | + * fsl_asrc_request_pair - Request ASRC pair |
---|
| 203 | + * @channels: number of channels |
---|
| 204 | + * @pair: pointer to pair |
---|
84 | 205 | * |
---|
85 | 206 | * It assigns pair by the order of A->C->B because allocation of pair B, |
---|
86 | 207 | * within range [ANCA, ANCA+ANCB-1], depends on the channels of pair A |
---|
.. | .. |
---|
89 | 210 | static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) |
---|
90 | 211 | { |
---|
91 | 212 | enum asrc_pair_index index = ASRC_INVALID_PAIR; |
---|
92 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
93 | | - struct device *dev = &asrc_priv->pdev->dev; |
---|
| 213 | + struct fsl_asrc *asrc = pair->asrc; |
---|
| 214 | + struct device *dev = &asrc->pdev->dev; |
---|
94 | 215 | unsigned long lock_flags; |
---|
95 | 216 | int i, ret = 0; |
---|
96 | 217 | |
---|
97 | | - spin_lock_irqsave(&asrc_priv->lock, lock_flags); |
---|
| 218 | + spin_lock_irqsave(&asrc->lock, lock_flags); |
---|
98 | 219 | |
---|
99 | 220 | for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) { |
---|
100 | | - if (asrc_priv->pair[i] != NULL) |
---|
| 221 | + if (asrc->pair[i] != NULL) |
---|
101 | 222 | continue; |
---|
102 | 223 | |
---|
103 | 224 | index = i; |
---|
.. | .. |
---|
109 | 230 | if (index == ASRC_INVALID_PAIR) { |
---|
110 | 231 | dev_err(dev, "all pairs are busy now\n"); |
---|
111 | 232 | ret = -EBUSY; |
---|
112 | | - } else if (asrc_priv->channel_avail < channels) { |
---|
| 233 | + } else if (asrc->channel_avail < channels) { |
---|
113 | 234 | dev_err(dev, "can't afford required channels: %d\n", channels); |
---|
114 | 235 | ret = -EINVAL; |
---|
115 | 236 | } else { |
---|
116 | | - asrc_priv->channel_avail -= channels; |
---|
117 | | - asrc_priv->pair[index] = pair; |
---|
| 237 | + asrc->channel_avail -= channels; |
---|
| 238 | + asrc->pair[index] = pair; |
---|
118 | 239 | pair->channels = channels; |
---|
119 | 240 | pair->index = index; |
---|
120 | 241 | } |
---|
121 | 242 | |
---|
122 | | - spin_unlock_irqrestore(&asrc_priv->lock, lock_flags); |
---|
| 243 | + spin_unlock_irqrestore(&asrc->lock, lock_flags); |
---|
123 | 244 | |
---|
124 | 245 | return ret; |
---|
125 | 246 | } |
---|
126 | 247 | |
---|
127 | 248 | /** |
---|
128 | | - * Release ASRC pair |
---|
| 249 | + * fsl_asrc_release_pair - Release ASRC pair |
---|
| 250 | + * @pair: pair to release |
---|
129 | 251 | * |
---|
130 | | - * It clears the resource from asrc_priv and releases the occupied channels. |
---|
| 252 | + * It clears the resource from asrc and releases the occupied channels. |
---|
131 | 253 | */ |
---|
132 | 254 | static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair) |
---|
133 | 255 | { |
---|
134 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 256 | + struct fsl_asrc *asrc = pair->asrc; |
---|
135 | 257 | enum asrc_pair_index index = pair->index; |
---|
136 | 258 | unsigned long lock_flags; |
---|
137 | 259 | |
---|
138 | 260 | /* Make sure the pair is disabled */ |
---|
139 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 261 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
140 | 262 | ASRCTR_ASRCEi_MASK(index), 0); |
---|
141 | 263 | |
---|
142 | | - spin_lock_irqsave(&asrc_priv->lock, lock_flags); |
---|
| 264 | + spin_lock_irqsave(&asrc->lock, lock_flags); |
---|
143 | 265 | |
---|
144 | | - asrc_priv->channel_avail += pair->channels; |
---|
145 | | - asrc_priv->pair[index] = NULL; |
---|
| 266 | + asrc->channel_avail += pair->channels; |
---|
| 267 | + asrc->pair[index] = NULL; |
---|
146 | 268 | pair->error = 0; |
---|
147 | 269 | |
---|
148 | | - spin_unlock_irqrestore(&asrc_priv->lock, lock_flags); |
---|
| 270 | + spin_unlock_irqrestore(&asrc->lock, lock_flags); |
---|
149 | 271 | } |
---|
150 | 272 | |
---|
151 | 273 | /** |
---|
152 | | - * Configure input and output thresholds |
---|
| 274 | + * fsl_asrc_set_watermarks- configure input and output thresholds |
---|
| 275 | + * @pair: pointer to pair |
---|
| 276 | + * @in: input threshold |
---|
| 277 | + * @out: output threshold |
---|
153 | 278 | */ |
---|
154 | 279 | static void fsl_asrc_set_watermarks(struct fsl_asrc_pair *pair, u32 in, u32 out) |
---|
155 | 280 | { |
---|
156 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 281 | + struct fsl_asrc *asrc = pair->asrc; |
---|
157 | 282 | enum asrc_pair_index index = pair->index; |
---|
158 | 283 | |
---|
159 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRMCR(index), |
---|
| 284 | + regmap_update_bits(asrc->regmap, REG_ASRMCR(index), |
---|
160 | 285 | ASRMCRi_EXTTHRSHi_MASK | |
---|
161 | 286 | ASRMCRi_INFIFO_THRESHOLD_MASK | |
---|
162 | 287 | ASRMCRi_OUTFIFO_THRESHOLD_MASK, |
---|
.. | .. |
---|
166 | 291 | } |
---|
167 | 292 | |
---|
168 | 293 | /** |
---|
169 | | - * Calculate the total divisor between asrck clock rate and sample rate |
---|
| 294 | + * fsl_asrc_cal_asrck_divisor - Calculate the total divisor between asrck clock rate and sample rate |
---|
| 295 | + * @pair: pointer to pair |
---|
| 296 | + * @div: divider |
---|
170 | 297 | * |
---|
171 | 298 | * It follows the formula clk_rate = samplerate * (2 ^ prescaler) * divider |
---|
172 | 299 | */ |
---|
.. | .. |
---|
182 | 309 | } |
---|
183 | 310 | |
---|
184 | 311 | /** |
---|
185 | | - * Calculate and set the ratio for Ideal Ratio mode only |
---|
| 312 | + * fsl_asrc_set_ideal_ratio - Calculate and set the ratio for Ideal Ratio mode only |
---|
| 313 | + * @pair: pointer to pair |
---|
| 314 | + * @inrate: input rate |
---|
| 315 | + * @outrate: output rate |
---|
186 | 316 | * |
---|
187 | 317 | * The ratio is a 32-bit fixed point value with 26 fractional bits. |
---|
188 | 318 | */ |
---|
189 | 319 | static int fsl_asrc_set_ideal_ratio(struct fsl_asrc_pair *pair, |
---|
190 | 320 | int inrate, int outrate) |
---|
191 | 321 | { |
---|
192 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 322 | + struct fsl_asrc *asrc = pair->asrc; |
---|
193 | 323 | enum asrc_pair_index index = pair->index; |
---|
194 | 324 | unsigned long ratio; |
---|
195 | 325 | int i; |
---|
.. | .. |
---|
218 | 348 | break; |
---|
219 | 349 | } |
---|
220 | 350 | |
---|
221 | | - regmap_write(asrc_priv->regmap, REG_ASRIDRL(index), ratio); |
---|
222 | | - regmap_write(asrc_priv->regmap, REG_ASRIDRH(index), ratio >> 24); |
---|
| 351 | + regmap_write(asrc->regmap, REG_ASRIDRL(index), ratio); |
---|
| 352 | + regmap_write(asrc->regmap, REG_ASRIDRH(index), ratio >> 24); |
---|
223 | 353 | |
---|
224 | 354 | return 0; |
---|
225 | 355 | } |
---|
226 | 356 | |
---|
227 | 357 | /** |
---|
228 | | - * Configure the assigned ASRC pair |
---|
| 358 | + * fsl_asrc_config_pair - Configure the assigned ASRC pair |
---|
| 359 | + * @pair: pointer to pair |
---|
| 360 | + * @use_ideal_rate: boolean configuration |
---|
229 | 361 | * |
---|
230 | 362 | * It configures those ASRC registers according to a configuration instance |
---|
231 | 363 | * of struct asrc_config which includes in/output sample rate, width, channel |
---|
232 | 364 | * and clock settings. |
---|
| 365 | + * |
---|
| 366 | + * Note: |
---|
| 367 | + * The ideal ratio configuration can work with a flexible clock rate setting. |
---|
| 368 | + * Using IDEAL_RATIO_RATE gives a faster converting speed but overloads ASRC. |
---|
| 369 | + * For a regular audio playback, the clock rate should not be slower than an |
---|
| 370 | + * clock rate aligning with the output sample rate; For a use case requiring |
---|
| 371 | + * faster conversion, set use_ideal_rate to have the faster speed. |
---|
233 | 372 | */ |
---|
234 | | -static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) |
---|
| 373 | +static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair, bool use_ideal_rate) |
---|
235 | 374 | { |
---|
236 | | - struct asrc_config *config = pair->config; |
---|
237 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 375 | + struct fsl_asrc_pair_priv *pair_priv = pair->private; |
---|
| 376 | + struct asrc_config *config = pair_priv->config; |
---|
| 377 | + struct fsl_asrc *asrc = pair->asrc; |
---|
| 378 | + struct fsl_asrc_priv *asrc_priv = asrc->private; |
---|
238 | 379 | enum asrc_pair_index index = pair->index; |
---|
| 380 | + enum asrc_word_width input_word_width; |
---|
| 381 | + enum asrc_word_width output_word_width; |
---|
239 | 382 | u32 inrate, outrate, indiv, outdiv; |
---|
240 | 383 | u32 clk_index[2], div[2]; |
---|
| 384 | + u64 clk_rate; |
---|
241 | 385 | int in, out, channels; |
---|
| 386 | + int pre_proc, post_proc; |
---|
242 | 387 | struct clk *clk; |
---|
243 | | - bool ideal; |
---|
| 388 | + bool ideal, div_avail; |
---|
244 | 389 | |
---|
245 | 390 | if (!config) { |
---|
246 | 391 | pair_err("invalid pair config\n"); |
---|
.. | .. |
---|
253 | 398 | return -EINVAL; |
---|
254 | 399 | } |
---|
255 | 400 | |
---|
256 | | - /* Validate output width */ |
---|
257 | | - if (config->output_word_width == ASRC_WIDTH_8_BIT) { |
---|
258 | | - pair_err("does not support 8bit width output\n"); |
---|
| 401 | + switch (snd_pcm_format_width(config->input_format)) { |
---|
| 402 | + case 8: |
---|
| 403 | + input_word_width = ASRC_WIDTH_8_BIT; |
---|
| 404 | + break; |
---|
| 405 | + case 16: |
---|
| 406 | + input_word_width = ASRC_WIDTH_16_BIT; |
---|
| 407 | + break; |
---|
| 408 | + case 24: |
---|
| 409 | + input_word_width = ASRC_WIDTH_24_BIT; |
---|
| 410 | + break; |
---|
| 411 | + default: |
---|
| 412 | + pair_err("does not support this input format, %d\n", |
---|
| 413 | + config->input_format); |
---|
| 414 | + return -EINVAL; |
---|
| 415 | + } |
---|
| 416 | + |
---|
| 417 | + switch (snd_pcm_format_width(config->output_format)) { |
---|
| 418 | + case 16: |
---|
| 419 | + output_word_width = ASRC_WIDTH_16_BIT; |
---|
| 420 | + break; |
---|
| 421 | + case 24: |
---|
| 422 | + output_word_width = ASRC_WIDTH_24_BIT; |
---|
| 423 | + break; |
---|
| 424 | + default: |
---|
| 425 | + pair_err("does not support this output format, %d\n", |
---|
| 426 | + config->output_format); |
---|
259 | 427 | return -EINVAL; |
---|
260 | 428 | } |
---|
261 | 429 | |
---|
.. | .. |
---|
264 | 432 | ideal = config->inclk == INCLK_NONE; |
---|
265 | 433 | |
---|
266 | 434 | /* Validate input and output sample rates */ |
---|
267 | | - for (in = 0; in < ARRAY_SIZE(supported_input_rate); in++) |
---|
268 | | - if (inrate == supported_input_rate[in]) |
---|
| 435 | + for (in = 0; in < ARRAY_SIZE(supported_asrc_rate); in++) |
---|
| 436 | + if (inrate == supported_asrc_rate[in]) |
---|
269 | 437 | break; |
---|
270 | 438 | |
---|
271 | | - if (in == ARRAY_SIZE(supported_input_rate)) { |
---|
| 439 | + if (in == ARRAY_SIZE(supported_asrc_rate)) { |
---|
272 | 440 | pair_err("unsupported input sample rate: %dHz\n", inrate); |
---|
273 | 441 | return -EINVAL; |
---|
274 | 442 | } |
---|
.. | .. |
---|
282 | 450 | return -EINVAL; |
---|
283 | 451 | } |
---|
284 | 452 | |
---|
285 | | - if ((outrate >= 8000 && outrate <= 30000) && |
---|
| 453 | + if ((outrate >= 5512 && outrate <= 30000) && |
---|
286 | 454 | (outrate > 24 * inrate || inrate > 8 * outrate)) { |
---|
287 | 455 | pair_err("exceed supported ratio range [1/24, 8] for \ |
---|
288 | 456 | inrate/outrate: %d/%d\n", inrate, outrate); |
---|
.. | .. |
---|
290 | 458 | } |
---|
291 | 459 | |
---|
292 | 460 | /* Validate input and output clock sources */ |
---|
293 | | - clk_index[IN] = clk_map[IN][config->inclk]; |
---|
294 | | - clk_index[OUT] = clk_map[OUT][config->outclk]; |
---|
| 461 | + clk_index[IN] = asrc_priv->clk_map[IN][config->inclk]; |
---|
| 462 | + clk_index[OUT] = asrc_priv->clk_map[OUT][config->outclk]; |
---|
295 | 463 | |
---|
296 | 464 | /* We only have output clock for ideal ratio mode */ |
---|
297 | 465 | clk = asrc_priv->asrck_clk[clk_index[ideal ? OUT : IN]]; |
---|
298 | 466 | |
---|
299 | | - div[IN] = clk_get_rate(clk) / inrate; |
---|
300 | | - if (div[IN] == 0) { |
---|
| 467 | + clk_rate = clk_get_rate(clk); |
---|
| 468 | + div_avail = fsl_asrc_divider_avail(clk_rate, inrate, &div[IN]); |
---|
| 469 | + |
---|
| 470 | + /* |
---|
| 471 | + * The divider range is [1, 1024], defined by the hardware. For non- |
---|
| 472 | + * ideal ratio configuration, clock rate has to be strictly aligned |
---|
| 473 | + * with the sample rate. For ideal ratio configuration, clock rates |
---|
| 474 | + * only result in different converting speeds. So remainder does not |
---|
| 475 | + * matter, as long as we keep the divider within its valid range. |
---|
| 476 | + */ |
---|
| 477 | + if (div[IN] == 0 || (!ideal && !div_avail)) { |
---|
301 | 478 | pair_err("failed to support input sample rate %dHz by asrck_%x\n", |
---|
302 | 479 | inrate, clk_index[ideal ? OUT : IN]); |
---|
303 | 480 | return -EINVAL; |
---|
304 | 481 | } |
---|
305 | 482 | |
---|
| 483 | + div[IN] = min_t(u32, 1024, div[IN]); |
---|
| 484 | + |
---|
306 | 485 | clk = asrc_priv->asrck_clk[clk_index[OUT]]; |
---|
307 | | - |
---|
308 | | - /* Use fixed output rate for Ideal Ratio mode (INCLK_NONE) */ |
---|
309 | | - if (ideal) |
---|
310 | | - div[OUT] = clk_get_rate(clk) / IDEAL_RATIO_RATE; |
---|
| 486 | + clk_rate = clk_get_rate(clk); |
---|
| 487 | + if (ideal && use_ideal_rate) |
---|
| 488 | + div_avail = fsl_asrc_divider_avail(clk_rate, IDEAL_RATIO_RATE, &div[OUT]); |
---|
311 | 489 | else |
---|
312 | | - div[OUT] = clk_get_rate(clk) / outrate; |
---|
| 490 | + div_avail = fsl_asrc_divider_avail(clk_rate, outrate, &div[OUT]); |
---|
313 | 491 | |
---|
314 | | - if (div[OUT] == 0) { |
---|
| 492 | + /* Output divider has the same limitation as the input one */ |
---|
| 493 | + if (div[OUT] == 0 || (!ideal && !div_avail)) { |
---|
315 | 494 | pair_err("failed to support output sample rate %dHz by asrck_%x\n", |
---|
316 | 495 | outrate, clk_index[OUT]); |
---|
317 | 496 | return -EINVAL; |
---|
318 | 497 | } |
---|
319 | 498 | |
---|
| 499 | + div[OUT] = min_t(u32, 1024, div[OUT]); |
---|
| 500 | + |
---|
320 | 501 | /* Set the channel number */ |
---|
321 | 502 | channels = config->channel_num; |
---|
322 | 503 | |
---|
323 | | - if (asrc_priv->channel_bits < 4) |
---|
| 504 | + if (asrc_priv->soc->channel_bits < 4) |
---|
324 | 505 | channels /= 2; |
---|
325 | 506 | |
---|
326 | 507 | /* Update channels for current pair */ |
---|
327 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCNCR, |
---|
328 | | - ASRCNCR_ANCi_MASK(index, asrc_priv->channel_bits), |
---|
329 | | - ASRCNCR_ANCi(index, channels, asrc_priv->channel_bits)); |
---|
| 508 | + regmap_update_bits(asrc->regmap, REG_ASRCNCR, |
---|
| 509 | + ASRCNCR_ANCi_MASK(index, asrc_priv->soc->channel_bits), |
---|
| 510 | + ASRCNCR_ANCi(index, channels, asrc_priv->soc->channel_bits)); |
---|
330 | 511 | |
---|
331 | 512 | /* Default setting: Automatic selection for processing mode */ |
---|
332 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 513 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
333 | 514 | ASRCTR_ATSi_MASK(index), ASRCTR_ATS(index)); |
---|
334 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 515 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
335 | 516 | ASRCTR_USRi_MASK(index), 0); |
---|
336 | 517 | |
---|
337 | 518 | /* Set the input and output clock sources */ |
---|
338 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCSR, |
---|
| 519 | + regmap_update_bits(asrc->regmap, REG_ASRCSR, |
---|
339 | 520 | ASRCSR_AICSi_MASK(index) | ASRCSR_AOCSi_MASK(index), |
---|
340 | 521 | ASRCSR_AICS(index, clk_index[IN]) | |
---|
341 | 522 | ASRCSR_AOCS(index, clk_index[OUT])); |
---|
.. | .. |
---|
345 | 526 | outdiv = fsl_asrc_cal_asrck_divisor(pair, div[OUT]); |
---|
346 | 527 | |
---|
347 | 528 | /* Suppose indiv and outdiv includes prescaler, so add its MASK too */ |
---|
348 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCDR(index), |
---|
| 529 | + regmap_update_bits(asrc->regmap, REG_ASRCDR(index), |
---|
349 | 530 | ASRCDRi_AOCPi_MASK(index) | ASRCDRi_AICPi_MASK(index) | |
---|
350 | 531 | ASRCDRi_AOCDi_MASK(index) | ASRCDRi_AICDi_MASK(index), |
---|
351 | 532 | ASRCDRi_AOCP(index, outdiv) | ASRCDRi_AICP(index, indiv)); |
---|
352 | 533 | |
---|
353 | 534 | /* Implement word_width configurations */ |
---|
354 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRMCR1(index), |
---|
| 535 | + regmap_update_bits(asrc->regmap, REG_ASRMCR1(index), |
---|
355 | 536 | ASRMCR1i_OW16_MASK | ASRMCR1i_IWD_MASK, |
---|
356 | | - ASRMCR1i_OW16(config->output_word_width) | |
---|
357 | | - ASRMCR1i_IWD(config->input_word_width)); |
---|
| 537 | + ASRMCR1i_OW16(output_word_width) | |
---|
| 538 | + ASRMCR1i_IWD(input_word_width)); |
---|
358 | 539 | |
---|
359 | 540 | /* Enable BUFFER STALL */ |
---|
360 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRMCR(index), |
---|
| 541 | + regmap_update_bits(asrc->regmap, REG_ASRMCR(index), |
---|
361 | 542 | ASRMCRi_BUFSTALLi_MASK, ASRMCRi_BUFSTALLi); |
---|
362 | 543 | |
---|
363 | 544 | /* Set default thresholds for input and output FIFO */ |
---|
.. | .. |
---|
369 | 550 | return 0; |
---|
370 | 551 | |
---|
371 | 552 | /* Clear ASTSx bit to use Ideal Ratio mode */ |
---|
372 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 553 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
373 | 554 | ASRCTR_ATSi_MASK(index), 0); |
---|
374 | 555 | |
---|
375 | 556 | /* Enable Ideal Ratio mode */ |
---|
376 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 557 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
377 | 558 | ASRCTR_IDRi_MASK(index) | ASRCTR_USRi_MASK(index), |
---|
378 | 559 | ASRCTR_IDR(index) | ASRCTR_USR(index)); |
---|
379 | 560 | |
---|
| 561 | + fsl_asrc_sel_proc(inrate, outrate, &pre_proc, &post_proc); |
---|
| 562 | + |
---|
380 | 563 | /* Apply configurations for pre- and post-processing */ |
---|
381 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCFG, |
---|
| 564 | + regmap_update_bits(asrc->regmap, REG_ASRCFG, |
---|
382 | 565 | ASRCFG_PREMODi_MASK(index) | ASRCFG_POSTMODi_MASK(index), |
---|
383 | | - ASRCFG_PREMOD(index, process_option[in][out][0]) | |
---|
384 | | - ASRCFG_POSTMOD(index, process_option[in][out][1])); |
---|
| 566 | + ASRCFG_PREMOD(index, pre_proc) | |
---|
| 567 | + ASRCFG_POSTMOD(index, post_proc)); |
---|
385 | 568 | |
---|
386 | 569 | return fsl_asrc_set_ideal_ratio(pair, inrate, outrate); |
---|
387 | 570 | } |
---|
388 | 571 | |
---|
389 | 572 | /** |
---|
390 | | - * Start the assigned ASRC pair |
---|
| 573 | + * fsl_asrc_start_pair - Start the assigned ASRC pair |
---|
| 574 | + * @pair: pointer to pair |
---|
391 | 575 | * |
---|
392 | 576 | * It enables the assigned pair and makes it stopped at the stall level. |
---|
393 | 577 | */ |
---|
394 | 578 | static void fsl_asrc_start_pair(struct fsl_asrc_pair *pair) |
---|
395 | 579 | { |
---|
396 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 580 | + struct fsl_asrc *asrc = pair->asrc; |
---|
397 | 581 | enum asrc_pair_index index = pair->index; |
---|
398 | 582 | int reg, retry = 10, i; |
---|
399 | 583 | |
---|
400 | 584 | /* Enable the current pair */ |
---|
401 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 585 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
402 | 586 | ASRCTR_ASRCEi_MASK(index), ASRCTR_ASRCE(index)); |
---|
403 | 587 | |
---|
404 | 588 | /* Wait for status of initialization */ |
---|
405 | 589 | do { |
---|
406 | 590 | udelay(5); |
---|
407 | | - regmap_read(asrc_priv->regmap, REG_ASRCFG, ®); |
---|
| 591 | + regmap_read(asrc->regmap, REG_ASRCFG, ®); |
---|
408 | 592 | reg &= ASRCFG_INIRQi_MASK(index); |
---|
409 | 593 | } while (!reg && --retry); |
---|
410 | 594 | |
---|
411 | 595 | /* Make the input fifo to ASRC STALL level */ |
---|
412 | | - regmap_read(asrc_priv->regmap, REG_ASRCNCR, ®); |
---|
| 596 | + regmap_read(asrc->regmap, REG_ASRCNCR, ®); |
---|
413 | 597 | for (i = 0; i < pair->channels * 4; i++) |
---|
414 | | - regmap_write(asrc_priv->regmap, REG_ASRDI(index), 0); |
---|
| 598 | + regmap_write(asrc->regmap, REG_ASRDI(index), 0); |
---|
415 | 599 | |
---|
416 | 600 | /* Enable overload interrupt */ |
---|
417 | | - regmap_write(asrc_priv->regmap, REG_ASRIER, ASRIER_AOLIE); |
---|
| 601 | + regmap_write(asrc->regmap, REG_ASRIER, ASRIER_AOLIE); |
---|
418 | 602 | } |
---|
419 | 603 | |
---|
420 | 604 | /** |
---|
421 | | - * Stop the assigned ASRC pair |
---|
| 605 | + * fsl_asrc_stop_pair - Stop the assigned ASRC pair |
---|
| 606 | + * @pair: pointer to pair |
---|
422 | 607 | */ |
---|
423 | 608 | static void fsl_asrc_stop_pair(struct fsl_asrc_pair *pair) |
---|
424 | 609 | { |
---|
425 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 610 | + struct fsl_asrc *asrc = pair->asrc; |
---|
426 | 611 | enum asrc_pair_index index = pair->index; |
---|
427 | 612 | |
---|
428 | 613 | /* Stop the current pair */ |
---|
429 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
| 614 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
430 | 615 | ASRCTR_ASRCEi_MASK(index), 0); |
---|
431 | 616 | } |
---|
432 | 617 | |
---|
433 | 618 | /** |
---|
434 | | - * Get DMA channel according to the pair and direction. |
---|
| 619 | + * fsl_asrc_get_dma_channel- Get DMA channel according to the pair and direction. |
---|
| 620 | + * @pair: pointer to pair |
---|
| 621 | + * @dir: DMA direction |
---|
435 | 622 | */ |
---|
436 | | -struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair, bool dir) |
---|
| 623 | +static struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair, |
---|
| 624 | + bool dir) |
---|
437 | 625 | { |
---|
438 | | - struct fsl_asrc *asrc_priv = pair->asrc_priv; |
---|
| 626 | + struct fsl_asrc *asrc = pair->asrc; |
---|
439 | 627 | enum asrc_pair_index index = pair->index; |
---|
440 | 628 | char name[4]; |
---|
441 | 629 | |
---|
442 | 630 | sprintf(name, "%cx%c", dir == IN ? 'r' : 't', index + 'a'); |
---|
443 | 631 | |
---|
444 | | - return dma_request_slave_channel(&asrc_priv->pdev->dev, name); |
---|
| 632 | + return dma_request_slave_channel(&asrc->pdev->dev, name); |
---|
445 | 633 | } |
---|
446 | | -EXPORT_SYMBOL_GPL(fsl_asrc_get_dma_channel); |
---|
| 634 | + |
---|
| 635 | +static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream, |
---|
| 636 | + struct snd_soc_dai *dai) |
---|
| 637 | +{ |
---|
| 638 | + struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai); |
---|
| 639 | + struct fsl_asrc_priv *asrc_priv = asrc->private; |
---|
| 640 | + |
---|
| 641 | + /* Odd channel number is not valid for older ASRC (channel_bits==3) */ |
---|
| 642 | + if (asrc_priv->soc->channel_bits == 3) |
---|
| 643 | + snd_pcm_hw_constraint_step(substream->runtime, 0, |
---|
| 644 | + SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
---|
| 645 | + |
---|
| 646 | + |
---|
| 647 | + return snd_pcm_hw_constraint_list(substream->runtime, 0, |
---|
| 648 | + SNDRV_PCM_HW_PARAM_RATE, &fsl_asrc_rate_constraints); |
---|
| 649 | +} |
---|
| 650 | + |
---|
| 651 | +/* Select proper clock source for internal ratio mode */ |
---|
| 652 | +static void fsl_asrc_select_clk(struct fsl_asrc_priv *asrc_priv, |
---|
| 653 | + struct fsl_asrc_pair *pair, |
---|
| 654 | + int in_rate, |
---|
| 655 | + int out_rate) |
---|
| 656 | +{ |
---|
| 657 | + struct fsl_asrc_pair_priv *pair_priv = pair->private; |
---|
| 658 | + struct asrc_config *config = pair_priv->config; |
---|
| 659 | + int rate[2], select_clk[2]; /* Array size 2 means IN and OUT */ |
---|
| 660 | + int clk_rate, clk_index; |
---|
| 661 | + int i = 0, j = 0; |
---|
| 662 | + |
---|
| 663 | + rate[IN] = in_rate; |
---|
| 664 | + rate[OUT] = out_rate; |
---|
| 665 | + |
---|
| 666 | + /* Select proper clock source for internal ratio mode */ |
---|
| 667 | + for (j = 0; j < 2; j++) { |
---|
| 668 | + for (i = 0; i < ASRC_CLK_MAP_LEN; i++) { |
---|
| 669 | + clk_index = asrc_priv->clk_map[j][i]; |
---|
| 670 | + clk_rate = clk_get_rate(asrc_priv->asrck_clk[clk_index]); |
---|
| 671 | + /* Only match a perfect clock source with no remainder */ |
---|
| 672 | + if (fsl_asrc_divider_avail(clk_rate, rate[j], NULL)) |
---|
| 673 | + break; |
---|
| 674 | + } |
---|
| 675 | + |
---|
| 676 | + select_clk[j] = i; |
---|
| 677 | + } |
---|
| 678 | + |
---|
| 679 | + /* Switch to ideal ratio mode if there is no proper clock source */ |
---|
| 680 | + if (select_clk[IN] == ASRC_CLK_MAP_LEN || select_clk[OUT] == ASRC_CLK_MAP_LEN) { |
---|
| 681 | + select_clk[IN] = INCLK_NONE; |
---|
| 682 | + select_clk[OUT] = OUTCLK_ASRCK1_CLK; |
---|
| 683 | + } |
---|
| 684 | + |
---|
| 685 | + config->inclk = select_clk[IN]; |
---|
| 686 | + config->outclk = select_clk[OUT]; |
---|
| 687 | +} |
---|
447 | 688 | |
---|
448 | 689 | static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream, |
---|
449 | 690 | struct snd_pcm_hw_params *params, |
---|
450 | 691 | struct snd_soc_dai *dai) |
---|
451 | 692 | { |
---|
452 | | - struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai); |
---|
453 | | - int width = params_width(params); |
---|
| 693 | + struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai); |
---|
| 694 | + struct fsl_asrc_priv *asrc_priv = asrc->private; |
---|
454 | 695 | struct snd_pcm_runtime *runtime = substream->runtime; |
---|
455 | 696 | struct fsl_asrc_pair *pair = runtime->private_data; |
---|
| 697 | + struct fsl_asrc_pair_priv *pair_priv = pair->private; |
---|
456 | 698 | unsigned int channels = params_channels(params); |
---|
457 | 699 | unsigned int rate = params_rate(params); |
---|
458 | 700 | struct asrc_config config; |
---|
459 | | - int word_width, ret; |
---|
| 701 | + int ret; |
---|
460 | 702 | |
---|
461 | 703 | ret = fsl_asrc_request_pair(channels, pair); |
---|
462 | 704 | if (ret) { |
---|
.. | .. |
---|
464 | 706 | return ret; |
---|
465 | 707 | } |
---|
466 | 708 | |
---|
467 | | - pair->config = &config; |
---|
468 | | - |
---|
469 | | - if (width == 16) |
---|
470 | | - width = ASRC_WIDTH_16_BIT; |
---|
471 | | - else |
---|
472 | | - width = ASRC_WIDTH_24_BIT; |
---|
473 | | - |
---|
474 | | - if (asrc_priv->asrc_width == 16) |
---|
475 | | - word_width = ASRC_WIDTH_16_BIT; |
---|
476 | | - else |
---|
477 | | - word_width = ASRC_WIDTH_24_BIT; |
---|
| 709 | + pair_priv->config = &config; |
---|
478 | 710 | |
---|
479 | 711 | config.pair = pair->index; |
---|
480 | 712 | config.channel_num = channels; |
---|
481 | | - config.inclk = INCLK_NONE; |
---|
482 | | - config.outclk = OUTCLK_ASRCK1_CLK; |
---|
483 | 713 | |
---|
484 | 714 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
---|
485 | | - config.input_word_width = width; |
---|
486 | | - config.output_word_width = word_width; |
---|
| 715 | + config.input_format = params_format(params); |
---|
| 716 | + config.output_format = asrc->asrc_format; |
---|
487 | 717 | config.input_sample_rate = rate; |
---|
488 | | - config.output_sample_rate = asrc_priv->asrc_rate; |
---|
| 718 | + config.output_sample_rate = asrc->asrc_rate; |
---|
489 | 719 | } else { |
---|
490 | | - config.input_word_width = word_width; |
---|
491 | | - config.output_word_width = width; |
---|
492 | | - config.input_sample_rate = asrc_priv->asrc_rate; |
---|
| 720 | + config.input_format = asrc->asrc_format; |
---|
| 721 | + config.output_format = params_format(params); |
---|
| 722 | + config.input_sample_rate = asrc->asrc_rate; |
---|
493 | 723 | config.output_sample_rate = rate; |
---|
494 | 724 | } |
---|
495 | 725 | |
---|
496 | | - ret = fsl_asrc_config_pair(pair); |
---|
| 726 | + fsl_asrc_select_clk(asrc_priv, pair, |
---|
| 727 | + config.input_sample_rate, |
---|
| 728 | + config.output_sample_rate); |
---|
| 729 | + |
---|
| 730 | + ret = fsl_asrc_config_pair(pair, false); |
---|
497 | 731 | if (ret) { |
---|
498 | 732 | dev_err(dai->dev, "fail to config asrc pair\n"); |
---|
499 | 733 | return ret; |
---|
.. | .. |
---|
539 | 773 | } |
---|
540 | 774 | |
---|
541 | 775 | static const struct snd_soc_dai_ops fsl_asrc_dai_ops = { |
---|
| 776 | + .startup = fsl_asrc_dai_startup, |
---|
542 | 777 | .hw_params = fsl_asrc_dai_hw_params, |
---|
543 | 778 | .hw_free = fsl_asrc_dai_hw_free, |
---|
544 | 779 | .trigger = fsl_asrc_dai_trigger, |
---|
.. | .. |
---|
546 | 781 | |
---|
547 | 782 | static int fsl_asrc_dai_probe(struct snd_soc_dai *dai) |
---|
548 | 783 | { |
---|
549 | | - struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai); |
---|
| 784 | + struct fsl_asrc *asrc = snd_soc_dai_get_drvdata(dai); |
---|
550 | 785 | |
---|
551 | | - snd_soc_dai_init_dma_data(dai, &asrc_priv->dma_params_tx, |
---|
552 | | - &asrc_priv->dma_params_rx); |
---|
| 786 | + snd_soc_dai_init_dma_data(dai, &asrc->dma_params_tx, |
---|
| 787 | + &asrc->dma_params_rx); |
---|
553 | 788 | |
---|
554 | 789 | return 0; |
---|
555 | 790 | } |
---|
556 | 791 | |
---|
557 | | -#define FSL_ASRC_RATES SNDRV_PCM_RATE_8000_192000 |
---|
558 | 792 | #define FSL_ASRC_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | \ |
---|
559 | 793 | SNDRV_PCM_FMTBIT_S16_LE | \ |
---|
560 | | - SNDRV_PCM_FMTBIT_S20_3LE) |
---|
| 794 | + SNDRV_PCM_FMTBIT_S24_3LE) |
---|
561 | 795 | |
---|
562 | 796 | static struct snd_soc_dai_driver fsl_asrc_dai = { |
---|
563 | 797 | .probe = fsl_asrc_dai_probe, |
---|
.. | .. |
---|
565 | 799 | .stream_name = "ASRC-Playback", |
---|
566 | 800 | .channels_min = 1, |
---|
567 | 801 | .channels_max = 10, |
---|
568 | | - .rates = FSL_ASRC_RATES, |
---|
569 | | - .formats = FSL_ASRC_FORMATS, |
---|
| 802 | + .rate_min = 5512, |
---|
| 803 | + .rate_max = 192000, |
---|
| 804 | + .rates = SNDRV_PCM_RATE_KNOT, |
---|
| 805 | + .formats = FSL_ASRC_FORMATS | |
---|
| 806 | + SNDRV_PCM_FMTBIT_S8, |
---|
570 | 807 | }, |
---|
571 | 808 | .capture = { |
---|
572 | 809 | .stream_name = "ASRC-Capture", |
---|
573 | 810 | .channels_min = 1, |
---|
574 | 811 | .channels_max = 10, |
---|
575 | | - .rates = FSL_ASRC_RATES, |
---|
| 812 | + .rate_min = 5512, |
---|
| 813 | + .rate_max = 192000, |
---|
| 814 | + .rates = SNDRV_PCM_RATE_KNOT, |
---|
576 | 815 | .formats = FSL_ASRC_FORMATS, |
---|
577 | 816 | }, |
---|
578 | 817 | .ops = &fsl_asrc_dai_ops, |
---|
.. | .. |
---|
722 | 961 | }; |
---|
723 | 962 | |
---|
724 | 963 | /** |
---|
725 | | - * Initialize ASRC registers with a default configurations |
---|
| 964 | + * fsl_asrc_init - Initialize ASRC registers with a default configuration |
---|
| 965 | + * @asrc: ASRC context |
---|
726 | 966 | */ |
---|
727 | | -static int fsl_asrc_init(struct fsl_asrc *asrc_priv) |
---|
| 967 | +static int fsl_asrc_init(struct fsl_asrc *asrc) |
---|
728 | 968 | { |
---|
| 969 | + unsigned long ipg_rate; |
---|
| 970 | + |
---|
729 | 971 | /* Halt ASRC internal FP when input FIFO needs data for pair A, B, C */ |
---|
730 | | - regmap_write(asrc_priv->regmap, REG_ASRCTR, ASRCTR_ASRCEN); |
---|
| 972 | + regmap_write(asrc->regmap, REG_ASRCTR, ASRCTR_ASRCEN); |
---|
731 | 973 | |
---|
732 | 974 | /* Disable interrupt by default */ |
---|
733 | | - regmap_write(asrc_priv->regmap, REG_ASRIER, 0x0); |
---|
| 975 | + regmap_write(asrc->regmap, REG_ASRIER, 0x0); |
---|
734 | 976 | |
---|
735 | 977 | /* Apply recommended settings for parameters from Reference Manual */ |
---|
736 | | - regmap_write(asrc_priv->regmap, REG_ASRPM1, 0x7fffff); |
---|
737 | | - regmap_write(asrc_priv->regmap, REG_ASRPM2, 0x255555); |
---|
738 | | - regmap_write(asrc_priv->regmap, REG_ASRPM3, 0xff7280); |
---|
739 | | - regmap_write(asrc_priv->regmap, REG_ASRPM4, 0xff7280); |
---|
740 | | - regmap_write(asrc_priv->regmap, REG_ASRPM5, 0xff7280); |
---|
| 978 | + regmap_write(asrc->regmap, REG_ASRPM1, 0x7fffff); |
---|
| 979 | + regmap_write(asrc->regmap, REG_ASRPM2, 0x255555); |
---|
| 980 | + regmap_write(asrc->regmap, REG_ASRPM3, 0xff7280); |
---|
| 981 | + regmap_write(asrc->regmap, REG_ASRPM4, 0xff7280); |
---|
| 982 | + regmap_write(asrc->regmap, REG_ASRPM5, 0xff7280); |
---|
741 | 983 | |
---|
742 | 984 | /* Base address for task queue FIFO. Set to 0x7C */ |
---|
743 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRTFR1, |
---|
| 985 | + regmap_update_bits(asrc->regmap, REG_ASRTFR1, |
---|
744 | 986 | ASRTFR1_TF_BASE_MASK, ASRTFR1_TF_BASE(0xfc)); |
---|
745 | 987 | |
---|
746 | | - /* Set the processing clock for 76KHz to 133M */ |
---|
747 | | - regmap_write(asrc_priv->regmap, REG_ASR76K, 0x06D6); |
---|
748 | | - |
---|
749 | | - /* Set the processing clock for 56KHz to 133M */ |
---|
750 | | - return regmap_write(asrc_priv->regmap, REG_ASR56K, 0x0947); |
---|
| 988 | + /* |
---|
| 989 | + * Set the period of the 76KHz and 56KHz sampling clocks based on |
---|
| 990 | + * the ASRC processing clock. |
---|
| 991 | + * On iMX6, ipg_clk = 133MHz, REG_ASR76K = 0x06D6, REG_ASR56K = 0x0947 |
---|
| 992 | + */ |
---|
| 993 | + ipg_rate = clk_get_rate(asrc->ipg_clk); |
---|
| 994 | + regmap_write(asrc->regmap, REG_ASR76K, ipg_rate / 76000); |
---|
| 995 | + return regmap_write(asrc->regmap, REG_ASR56K, ipg_rate / 56000); |
---|
751 | 996 | } |
---|
752 | 997 | |
---|
753 | 998 | /** |
---|
754 | | - * Interrupt handler for ASRC |
---|
| 999 | + * fsl_asrc_isr- Interrupt handler for ASRC |
---|
| 1000 | + * @irq: irq number |
---|
| 1001 | + * @dev_id: ASRC context |
---|
755 | 1002 | */ |
---|
756 | 1003 | static irqreturn_t fsl_asrc_isr(int irq, void *dev_id) |
---|
757 | 1004 | { |
---|
758 | | - struct fsl_asrc *asrc_priv = (struct fsl_asrc *)dev_id; |
---|
759 | | - struct device *dev = &asrc_priv->pdev->dev; |
---|
| 1005 | + struct fsl_asrc *asrc = (struct fsl_asrc *)dev_id; |
---|
| 1006 | + struct device *dev = &asrc->pdev->dev; |
---|
760 | 1007 | enum asrc_pair_index index; |
---|
761 | 1008 | u32 status; |
---|
762 | 1009 | |
---|
763 | | - regmap_read(asrc_priv->regmap, REG_ASRSTR, &status); |
---|
| 1010 | + regmap_read(asrc->regmap, REG_ASRSTR, &status); |
---|
764 | 1011 | |
---|
765 | 1012 | /* Clean overload error */ |
---|
766 | | - regmap_write(asrc_priv->regmap, REG_ASRSTR, ASRSTR_AOLE); |
---|
| 1013 | + regmap_write(asrc->regmap, REG_ASRSTR, ASRSTR_AOLE); |
---|
767 | 1014 | |
---|
768 | 1015 | /* |
---|
769 | 1016 | * We here use dev_dbg() for all exceptions because ASRC itself does |
---|
.. | .. |
---|
771 | 1018 | * interrupt would result a ridged conversion. |
---|
772 | 1019 | */ |
---|
773 | 1020 | for (index = ASRC_PAIR_A; index < ASRC_PAIR_MAX_NUM; index++) { |
---|
774 | | - if (!asrc_priv->pair[index]) |
---|
| 1021 | + if (!asrc->pair[index]) |
---|
775 | 1022 | continue; |
---|
776 | 1023 | |
---|
777 | 1024 | if (status & ASRSTR_ATQOL) { |
---|
778 | | - asrc_priv->pair[index]->error |= ASRC_TASK_Q_OVERLOAD; |
---|
| 1025 | + asrc->pair[index]->error |= ASRC_TASK_Q_OVERLOAD; |
---|
779 | 1026 | dev_dbg(dev, "ASRC Task Queue FIFO overload\n"); |
---|
780 | 1027 | } |
---|
781 | 1028 | |
---|
782 | 1029 | if (status & ASRSTR_AOOL(index)) { |
---|
783 | | - asrc_priv->pair[index]->error |= ASRC_OUTPUT_TASK_OVERLOAD; |
---|
| 1030 | + asrc->pair[index]->error |= ASRC_OUTPUT_TASK_OVERLOAD; |
---|
784 | 1031 | pair_dbg("Output Task Overload\n"); |
---|
785 | 1032 | } |
---|
786 | 1033 | |
---|
787 | 1034 | if (status & ASRSTR_AIOL(index)) { |
---|
788 | | - asrc_priv->pair[index]->error |= ASRC_INPUT_TASK_OVERLOAD; |
---|
| 1035 | + asrc->pair[index]->error |= ASRC_INPUT_TASK_OVERLOAD; |
---|
789 | 1036 | pair_dbg("Input Task Overload\n"); |
---|
790 | 1037 | } |
---|
791 | 1038 | |
---|
792 | 1039 | if (status & ASRSTR_AODO(index)) { |
---|
793 | | - asrc_priv->pair[index]->error |= ASRC_OUTPUT_BUFFER_OVERFLOW; |
---|
| 1040 | + asrc->pair[index]->error |= ASRC_OUTPUT_BUFFER_OVERFLOW; |
---|
794 | 1041 | pair_dbg("Output Data Buffer has overflowed\n"); |
---|
795 | 1042 | } |
---|
796 | 1043 | |
---|
797 | 1044 | if (status & ASRSTR_AIDU(index)) { |
---|
798 | | - asrc_priv->pair[index]->error |= ASRC_INPUT_BUFFER_UNDERRUN; |
---|
| 1045 | + asrc->pair[index]->error |= ASRC_INPUT_BUFFER_UNDERRUN; |
---|
799 | 1046 | pair_dbg("Input Data Buffer has underflowed\n"); |
---|
800 | 1047 | } |
---|
801 | 1048 | } |
---|
.. | .. |
---|
803 | 1050 | return IRQ_HANDLED; |
---|
804 | 1051 | } |
---|
805 | 1052 | |
---|
| 1053 | +static int fsl_asrc_get_fifo_addr(u8 dir, enum asrc_pair_index index) |
---|
| 1054 | +{ |
---|
| 1055 | + return REG_ASRDx(dir, index); |
---|
| 1056 | +} |
---|
| 1057 | + |
---|
806 | 1058 | static int fsl_asrc_probe(struct platform_device *pdev) |
---|
807 | 1059 | { |
---|
808 | 1060 | struct device_node *np = pdev->dev.of_node; |
---|
809 | | - struct fsl_asrc *asrc_priv; |
---|
| 1061 | + struct fsl_asrc_priv *asrc_priv; |
---|
| 1062 | + struct fsl_asrc *asrc; |
---|
810 | 1063 | struct resource *res; |
---|
811 | 1064 | void __iomem *regs; |
---|
812 | 1065 | int irq, ret, i; |
---|
| 1066 | + u32 map_idx; |
---|
813 | 1067 | char tmp[16]; |
---|
| 1068 | + u32 width; |
---|
| 1069 | + |
---|
| 1070 | + asrc = devm_kzalloc(&pdev->dev, sizeof(*asrc), GFP_KERNEL); |
---|
| 1071 | + if (!asrc) |
---|
| 1072 | + return -ENOMEM; |
---|
814 | 1073 | |
---|
815 | 1074 | asrc_priv = devm_kzalloc(&pdev->dev, sizeof(*asrc_priv), GFP_KERNEL); |
---|
816 | 1075 | if (!asrc_priv) |
---|
817 | 1076 | return -ENOMEM; |
---|
818 | 1077 | |
---|
819 | | - asrc_priv->pdev = pdev; |
---|
| 1078 | + asrc->pdev = pdev; |
---|
| 1079 | + asrc->private = asrc_priv; |
---|
820 | 1080 | |
---|
821 | 1081 | /* Get the addresses and IRQ */ |
---|
822 | 1082 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
.. | .. |
---|
824 | 1084 | if (IS_ERR(regs)) |
---|
825 | 1085 | return PTR_ERR(regs); |
---|
826 | 1086 | |
---|
827 | | - asrc_priv->paddr = res->start; |
---|
| 1087 | + asrc->paddr = res->start; |
---|
828 | 1088 | |
---|
829 | | - asrc_priv->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "mem", regs, |
---|
830 | | - &fsl_asrc_regmap_config); |
---|
831 | | - if (IS_ERR(asrc_priv->regmap)) { |
---|
| 1089 | + asrc->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "mem", regs, |
---|
| 1090 | + &fsl_asrc_regmap_config); |
---|
| 1091 | + if (IS_ERR(asrc->regmap)) { |
---|
832 | 1092 | dev_err(&pdev->dev, "failed to init regmap\n"); |
---|
833 | | - return PTR_ERR(asrc_priv->regmap); |
---|
| 1093 | + return PTR_ERR(asrc->regmap); |
---|
834 | 1094 | } |
---|
835 | 1095 | |
---|
836 | 1096 | irq = platform_get_irq(pdev, 0); |
---|
837 | | - if (irq < 0) { |
---|
838 | | - dev_err(&pdev->dev, "no irq for node %s\n", pdev->name); |
---|
| 1097 | + if (irq < 0) |
---|
839 | 1098 | return irq; |
---|
840 | | - } |
---|
841 | 1099 | |
---|
842 | 1100 | ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0, |
---|
843 | | - dev_name(&pdev->dev), asrc_priv); |
---|
| 1101 | + dev_name(&pdev->dev), asrc); |
---|
844 | 1102 | if (ret) { |
---|
845 | 1103 | dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret); |
---|
846 | 1104 | return ret; |
---|
847 | 1105 | } |
---|
848 | 1106 | |
---|
849 | | - asrc_priv->mem_clk = devm_clk_get(&pdev->dev, "mem"); |
---|
850 | | - if (IS_ERR(asrc_priv->mem_clk)) { |
---|
| 1107 | + asrc->mem_clk = devm_clk_get(&pdev->dev, "mem"); |
---|
| 1108 | + if (IS_ERR(asrc->mem_clk)) { |
---|
851 | 1109 | dev_err(&pdev->dev, "failed to get mem clock\n"); |
---|
852 | | - return PTR_ERR(asrc_priv->mem_clk); |
---|
| 1110 | + return PTR_ERR(asrc->mem_clk); |
---|
853 | 1111 | } |
---|
854 | 1112 | |
---|
855 | | - asrc_priv->ipg_clk = devm_clk_get(&pdev->dev, "ipg"); |
---|
856 | | - if (IS_ERR(asrc_priv->ipg_clk)) { |
---|
| 1113 | + asrc->ipg_clk = devm_clk_get(&pdev->dev, "ipg"); |
---|
| 1114 | + if (IS_ERR(asrc->ipg_clk)) { |
---|
857 | 1115 | dev_err(&pdev->dev, "failed to get ipg clock\n"); |
---|
858 | | - return PTR_ERR(asrc_priv->ipg_clk); |
---|
| 1116 | + return PTR_ERR(asrc->ipg_clk); |
---|
859 | 1117 | } |
---|
860 | 1118 | |
---|
861 | | - asrc_priv->spba_clk = devm_clk_get(&pdev->dev, "spba"); |
---|
862 | | - if (IS_ERR(asrc_priv->spba_clk)) |
---|
| 1119 | + asrc->spba_clk = devm_clk_get(&pdev->dev, "spba"); |
---|
| 1120 | + if (IS_ERR(asrc->spba_clk)) |
---|
863 | 1121 | dev_warn(&pdev->dev, "failed to get spba clock\n"); |
---|
864 | 1122 | |
---|
865 | 1123 | for (i = 0; i < ASRC_CLK_MAX_NUM; i++) { |
---|
.. | .. |
---|
871 | 1129 | } |
---|
872 | 1130 | } |
---|
873 | 1131 | |
---|
874 | | - if (of_device_is_compatible(np, "fsl,imx35-asrc")) { |
---|
875 | | - asrc_priv->channel_bits = 3; |
---|
876 | | - clk_map[IN] = input_clk_map_imx35; |
---|
877 | | - clk_map[OUT] = output_clk_map_imx35; |
---|
878 | | - } else { |
---|
879 | | - asrc_priv->channel_bits = 4; |
---|
880 | | - clk_map[IN] = input_clk_map_imx53; |
---|
881 | | - clk_map[OUT] = output_clk_map_imx53; |
---|
| 1132 | + asrc_priv->soc = of_device_get_match_data(&pdev->dev); |
---|
| 1133 | + if (!asrc_priv->soc) { |
---|
| 1134 | + dev_err(&pdev->dev, "failed to get soc data\n"); |
---|
| 1135 | + return -ENODEV; |
---|
882 | 1136 | } |
---|
883 | 1137 | |
---|
884 | | - ret = fsl_asrc_init(asrc_priv); |
---|
| 1138 | + asrc->use_edma = asrc_priv->soc->use_edma; |
---|
| 1139 | + asrc->get_dma_channel = fsl_asrc_get_dma_channel; |
---|
| 1140 | + asrc->request_pair = fsl_asrc_request_pair; |
---|
| 1141 | + asrc->release_pair = fsl_asrc_release_pair; |
---|
| 1142 | + asrc->get_fifo_addr = fsl_asrc_get_fifo_addr; |
---|
| 1143 | + asrc->pair_priv_size = sizeof(struct fsl_asrc_pair_priv); |
---|
| 1144 | + |
---|
| 1145 | + if (of_device_is_compatible(np, "fsl,imx35-asrc")) { |
---|
| 1146 | + asrc_priv->clk_map[IN] = input_clk_map_imx35; |
---|
| 1147 | + asrc_priv->clk_map[OUT] = output_clk_map_imx35; |
---|
| 1148 | + } else if (of_device_is_compatible(np, "fsl,imx53-asrc")) { |
---|
| 1149 | + asrc_priv->clk_map[IN] = input_clk_map_imx53; |
---|
| 1150 | + asrc_priv->clk_map[OUT] = output_clk_map_imx53; |
---|
| 1151 | + } else if (of_device_is_compatible(np, "fsl,imx8qm-asrc") || |
---|
| 1152 | + of_device_is_compatible(np, "fsl,imx8qxp-asrc")) { |
---|
| 1153 | + ret = of_property_read_u32(np, "fsl,asrc-clk-map", &map_idx); |
---|
| 1154 | + if (ret) { |
---|
| 1155 | + dev_err(&pdev->dev, "failed to get clk map index\n"); |
---|
| 1156 | + return ret; |
---|
| 1157 | + } |
---|
| 1158 | + |
---|
| 1159 | + if (map_idx > 1) { |
---|
| 1160 | + dev_err(&pdev->dev, "unsupported clk map index\n"); |
---|
| 1161 | + return -EINVAL; |
---|
| 1162 | + } |
---|
| 1163 | + if (of_device_is_compatible(np, "fsl,imx8qm-asrc")) { |
---|
| 1164 | + asrc_priv->clk_map[IN] = clk_map_imx8qm[map_idx]; |
---|
| 1165 | + asrc_priv->clk_map[OUT] = clk_map_imx8qm[map_idx]; |
---|
| 1166 | + } else { |
---|
| 1167 | + asrc_priv->clk_map[IN] = clk_map_imx8qxp[map_idx]; |
---|
| 1168 | + asrc_priv->clk_map[OUT] = clk_map_imx8qxp[map_idx]; |
---|
| 1169 | + } |
---|
| 1170 | + } |
---|
| 1171 | + |
---|
| 1172 | + ret = fsl_asrc_init(asrc); |
---|
885 | 1173 | if (ret) { |
---|
886 | 1174 | dev_err(&pdev->dev, "failed to init asrc %d\n", ret); |
---|
887 | 1175 | return ret; |
---|
888 | 1176 | } |
---|
889 | 1177 | |
---|
890 | | - asrc_priv->channel_avail = 10; |
---|
| 1178 | + asrc->channel_avail = 10; |
---|
891 | 1179 | |
---|
892 | 1180 | ret = of_property_read_u32(np, "fsl,asrc-rate", |
---|
893 | | - &asrc_priv->asrc_rate); |
---|
| 1181 | + &asrc->asrc_rate); |
---|
894 | 1182 | if (ret) { |
---|
895 | 1183 | dev_err(&pdev->dev, "failed to get output rate\n"); |
---|
896 | 1184 | return ret; |
---|
897 | 1185 | } |
---|
898 | 1186 | |
---|
899 | | - ret = of_property_read_u32(np, "fsl,asrc-width", |
---|
900 | | - &asrc_priv->asrc_width); |
---|
| 1187 | + ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format); |
---|
901 | 1188 | if (ret) { |
---|
902 | | - dev_err(&pdev->dev, "failed to get output width\n"); |
---|
903 | | - return ret; |
---|
| 1189 | + ret = of_property_read_u32(np, "fsl,asrc-width", &width); |
---|
| 1190 | + if (ret) { |
---|
| 1191 | + dev_err(&pdev->dev, "failed to decide output format\n"); |
---|
| 1192 | + return ret; |
---|
| 1193 | + } |
---|
| 1194 | + |
---|
| 1195 | + switch (width) { |
---|
| 1196 | + case 16: |
---|
| 1197 | + asrc->asrc_format = SNDRV_PCM_FORMAT_S16_LE; |
---|
| 1198 | + break; |
---|
| 1199 | + case 24: |
---|
| 1200 | + asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE; |
---|
| 1201 | + break; |
---|
| 1202 | + default: |
---|
| 1203 | + dev_warn(&pdev->dev, |
---|
| 1204 | + "unsupported width, use default S24_LE\n"); |
---|
| 1205 | + asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE; |
---|
| 1206 | + break; |
---|
| 1207 | + } |
---|
904 | 1208 | } |
---|
905 | 1209 | |
---|
906 | | - if (asrc_priv->asrc_width != 16 && asrc_priv->asrc_width != 24) { |
---|
907 | | - dev_warn(&pdev->dev, "unsupported width, switching to 24bit\n"); |
---|
908 | | - asrc_priv->asrc_width = 24; |
---|
| 1210 | + if (!(FSL_ASRC_FORMATS & (1ULL << asrc->asrc_format))) { |
---|
| 1211 | + dev_warn(&pdev->dev, "unsupported width, use default S24_LE\n"); |
---|
| 1212 | + asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE; |
---|
909 | 1213 | } |
---|
910 | 1214 | |
---|
911 | | - platform_set_drvdata(pdev, asrc_priv); |
---|
| 1215 | + platform_set_drvdata(pdev, asrc); |
---|
912 | 1216 | pm_runtime_enable(&pdev->dev); |
---|
913 | | - spin_lock_init(&asrc_priv->lock); |
---|
| 1217 | + spin_lock_init(&asrc->lock); |
---|
| 1218 | + regcache_cache_only(asrc->regmap, true); |
---|
914 | 1219 | |
---|
915 | 1220 | ret = devm_snd_soc_register_component(&pdev->dev, &fsl_asrc_component, |
---|
916 | 1221 | &fsl_asrc_dai, 1); |
---|
.. | .. |
---|
925 | 1230 | #ifdef CONFIG_PM |
---|
926 | 1231 | static int fsl_asrc_runtime_resume(struct device *dev) |
---|
927 | 1232 | { |
---|
928 | | - struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); |
---|
| 1233 | + struct fsl_asrc *asrc = dev_get_drvdata(dev); |
---|
| 1234 | + struct fsl_asrc_priv *asrc_priv = asrc->private; |
---|
929 | 1235 | int i, ret; |
---|
| 1236 | + u32 asrctr; |
---|
930 | 1237 | |
---|
931 | | - ret = clk_prepare_enable(asrc_priv->mem_clk); |
---|
| 1238 | + ret = clk_prepare_enable(asrc->mem_clk); |
---|
932 | 1239 | if (ret) |
---|
933 | 1240 | return ret; |
---|
934 | | - ret = clk_prepare_enable(asrc_priv->ipg_clk); |
---|
| 1241 | + ret = clk_prepare_enable(asrc->ipg_clk); |
---|
935 | 1242 | if (ret) |
---|
936 | 1243 | goto disable_mem_clk; |
---|
937 | | - if (!IS_ERR(asrc_priv->spba_clk)) { |
---|
938 | | - ret = clk_prepare_enable(asrc_priv->spba_clk); |
---|
| 1244 | + if (!IS_ERR(asrc->spba_clk)) { |
---|
| 1245 | + ret = clk_prepare_enable(asrc->spba_clk); |
---|
939 | 1246 | if (ret) |
---|
940 | 1247 | goto disable_ipg_clk; |
---|
941 | 1248 | } |
---|
.. | .. |
---|
945 | 1252 | goto disable_asrck_clk; |
---|
946 | 1253 | } |
---|
947 | 1254 | |
---|
| 1255 | + /* Stop all pairs provisionally */ |
---|
| 1256 | + regmap_read(asrc->regmap, REG_ASRCTR, &asrctr); |
---|
| 1257 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
| 1258 | + ASRCTR_ASRCEi_ALL_MASK, 0); |
---|
| 1259 | + |
---|
| 1260 | + /* Restore all registers */ |
---|
| 1261 | + regcache_cache_only(asrc->regmap, false); |
---|
| 1262 | + regcache_mark_dirty(asrc->regmap); |
---|
| 1263 | + regcache_sync(asrc->regmap); |
---|
| 1264 | + |
---|
| 1265 | + regmap_update_bits(asrc->regmap, REG_ASRCFG, |
---|
| 1266 | + ASRCFG_NDPRi_ALL_MASK | ASRCFG_POSTMODi_ALL_MASK | |
---|
| 1267 | + ASRCFG_PREMODi_ALL_MASK, asrc_priv->regcache_cfg); |
---|
| 1268 | + |
---|
| 1269 | + /* Restart enabled pairs */ |
---|
| 1270 | + regmap_update_bits(asrc->regmap, REG_ASRCTR, |
---|
| 1271 | + ASRCTR_ASRCEi_ALL_MASK, asrctr); |
---|
| 1272 | + |
---|
948 | 1273 | return 0; |
---|
949 | 1274 | |
---|
950 | 1275 | disable_asrck_clk: |
---|
951 | 1276 | for (i--; i >= 0; i--) |
---|
952 | 1277 | clk_disable_unprepare(asrc_priv->asrck_clk[i]); |
---|
953 | | - if (!IS_ERR(asrc_priv->spba_clk)) |
---|
954 | | - clk_disable_unprepare(asrc_priv->spba_clk); |
---|
| 1278 | + if (!IS_ERR(asrc->spba_clk)) |
---|
| 1279 | + clk_disable_unprepare(asrc->spba_clk); |
---|
955 | 1280 | disable_ipg_clk: |
---|
956 | | - clk_disable_unprepare(asrc_priv->ipg_clk); |
---|
| 1281 | + clk_disable_unprepare(asrc->ipg_clk); |
---|
957 | 1282 | disable_mem_clk: |
---|
958 | | - clk_disable_unprepare(asrc_priv->mem_clk); |
---|
| 1283 | + clk_disable_unprepare(asrc->mem_clk); |
---|
959 | 1284 | return ret; |
---|
960 | 1285 | } |
---|
961 | 1286 | |
---|
962 | 1287 | static int fsl_asrc_runtime_suspend(struct device *dev) |
---|
963 | 1288 | { |
---|
964 | | - struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); |
---|
| 1289 | + struct fsl_asrc *asrc = dev_get_drvdata(dev); |
---|
| 1290 | + struct fsl_asrc_priv *asrc_priv = asrc->private; |
---|
965 | 1291 | int i; |
---|
| 1292 | + |
---|
| 1293 | + regmap_read(asrc->regmap, REG_ASRCFG, |
---|
| 1294 | + &asrc_priv->regcache_cfg); |
---|
| 1295 | + |
---|
| 1296 | + regcache_cache_only(asrc->regmap, true); |
---|
966 | 1297 | |
---|
967 | 1298 | for (i = 0; i < ASRC_CLK_MAX_NUM; i++) |
---|
968 | 1299 | clk_disable_unprepare(asrc_priv->asrck_clk[i]); |
---|
969 | | - if (!IS_ERR(asrc_priv->spba_clk)) |
---|
970 | | - clk_disable_unprepare(asrc_priv->spba_clk); |
---|
971 | | - clk_disable_unprepare(asrc_priv->ipg_clk); |
---|
972 | | - clk_disable_unprepare(asrc_priv->mem_clk); |
---|
| 1300 | + if (!IS_ERR(asrc->spba_clk)) |
---|
| 1301 | + clk_disable_unprepare(asrc->spba_clk); |
---|
| 1302 | + clk_disable_unprepare(asrc->ipg_clk); |
---|
| 1303 | + clk_disable_unprepare(asrc->mem_clk); |
---|
973 | 1304 | |
---|
974 | 1305 | return 0; |
---|
975 | 1306 | } |
---|
976 | 1307 | #endif /* CONFIG_PM */ |
---|
977 | 1308 | |
---|
978 | | -#ifdef CONFIG_PM_SLEEP |
---|
979 | | -static int fsl_asrc_suspend(struct device *dev) |
---|
980 | | -{ |
---|
981 | | - struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); |
---|
982 | | - |
---|
983 | | - regmap_read(asrc_priv->regmap, REG_ASRCFG, |
---|
984 | | - &asrc_priv->regcache_cfg); |
---|
985 | | - |
---|
986 | | - regcache_cache_only(asrc_priv->regmap, true); |
---|
987 | | - regcache_mark_dirty(asrc_priv->regmap); |
---|
988 | | - |
---|
989 | | - return 0; |
---|
990 | | -} |
---|
991 | | - |
---|
992 | | -static int fsl_asrc_resume(struct device *dev) |
---|
993 | | -{ |
---|
994 | | - struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); |
---|
995 | | - u32 asrctr; |
---|
996 | | - |
---|
997 | | - /* Stop all pairs provisionally */ |
---|
998 | | - regmap_read(asrc_priv->regmap, REG_ASRCTR, &asrctr); |
---|
999 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
1000 | | - ASRCTR_ASRCEi_ALL_MASK, 0); |
---|
1001 | | - |
---|
1002 | | - /* Restore all registers */ |
---|
1003 | | - regcache_cache_only(asrc_priv->regmap, false); |
---|
1004 | | - regcache_sync(asrc_priv->regmap); |
---|
1005 | | - |
---|
1006 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCFG, |
---|
1007 | | - ASRCFG_NDPRi_ALL_MASK | ASRCFG_POSTMODi_ALL_MASK | |
---|
1008 | | - ASRCFG_PREMODi_ALL_MASK, asrc_priv->regcache_cfg); |
---|
1009 | | - |
---|
1010 | | - /* Restart enabled pairs */ |
---|
1011 | | - regmap_update_bits(asrc_priv->regmap, REG_ASRCTR, |
---|
1012 | | - ASRCTR_ASRCEi_ALL_MASK, asrctr); |
---|
1013 | | - |
---|
1014 | | - return 0; |
---|
1015 | | -} |
---|
1016 | | -#endif /* CONFIG_PM_SLEEP */ |
---|
1017 | | - |
---|
1018 | 1309 | static const struct dev_pm_ops fsl_asrc_pm = { |
---|
1019 | 1310 | SET_RUNTIME_PM_OPS(fsl_asrc_runtime_suspend, fsl_asrc_runtime_resume, NULL) |
---|
1020 | | - SET_SYSTEM_SLEEP_PM_OPS(fsl_asrc_suspend, fsl_asrc_resume) |
---|
| 1311 | + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, |
---|
| 1312 | + pm_runtime_force_resume) |
---|
| 1313 | +}; |
---|
| 1314 | + |
---|
| 1315 | +static const struct fsl_asrc_soc_data fsl_asrc_imx35_data = { |
---|
| 1316 | + .use_edma = false, |
---|
| 1317 | + .channel_bits = 3, |
---|
| 1318 | +}; |
---|
| 1319 | + |
---|
| 1320 | +static const struct fsl_asrc_soc_data fsl_asrc_imx53_data = { |
---|
| 1321 | + .use_edma = false, |
---|
| 1322 | + .channel_bits = 4, |
---|
| 1323 | +}; |
---|
| 1324 | + |
---|
| 1325 | +static const struct fsl_asrc_soc_data fsl_asrc_imx8qm_data = { |
---|
| 1326 | + .use_edma = true, |
---|
| 1327 | + .channel_bits = 4, |
---|
| 1328 | +}; |
---|
| 1329 | + |
---|
| 1330 | +static const struct fsl_asrc_soc_data fsl_asrc_imx8qxp_data = { |
---|
| 1331 | + .use_edma = true, |
---|
| 1332 | + .channel_bits = 4, |
---|
1021 | 1333 | }; |
---|
1022 | 1334 | |
---|
1023 | 1335 | static const struct of_device_id fsl_asrc_ids[] = { |
---|
1024 | | - { .compatible = "fsl,imx35-asrc", }, |
---|
1025 | | - { .compatible = "fsl,imx53-asrc", }, |
---|
| 1336 | + { .compatible = "fsl,imx35-asrc", .data = &fsl_asrc_imx35_data }, |
---|
| 1337 | + { .compatible = "fsl,imx53-asrc", .data = &fsl_asrc_imx53_data }, |
---|
| 1338 | + { .compatible = "fsl,imx8qm-asrc", .data = &fsl_asrc_imx8qm_data }, |
---|
| 1339 | + { .compatible = "fsl,imx8qxp-asrc", .data = &fsl_asrc_imx8qxp_data }, |
---|
1026 | 1340 | {} |
---|
1027 | 1341 | }; |
---|
1028 | 1342 | MODULE_DEVICE_TABLE(of, fsl_asrc_ids); |
---|