Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'ib-from-asoc-3.16', 'ib-from-pm-3.16', 'ib-from-regulator-3.16', 'ib-mfd-gpio-3.16' and 'ib-mfd-mmc-memstick-3.16', tags 'ib-mfd-extcon-3.16', 'ib-mfd-omap-3.16' and 'ib-mfd-regulator-3.16' into ibs-for-mfd-merged

Lee Jones 28fee3fa 4b660a7f

+3670 -500
+19
Documentation/cpu-freq/cpu-drivers.txt
··· 228 228 stage. Just pass the values to this function, and the unsigned int 229 229 index returns the number of the frequency table entry which contains 230 230 the frequency the CPU shall be set to. 231 + 232 + The following macros can be used as iterators over cpufreq_frequency_table: 233 + 234 + cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency 235 + table. 236 + 237 + cpufreq-for_each_valid_entry(pos, table) - iterates over all entries, 238 + excluding CPUFREQ_ENTRY_INVALID frequencies. 239 + Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and 240 + "table" - the cpufreq_frequency_table * you want to iterate over. 241 + 242 + For example: 243 + 244 + struct cpufreq_frequency_table *pos, *driver_freq_table; 245 + 246 + cpufreq_for_each_entry(pos, driver_freq_table) { 247 + /* Do something with pos */ 248 + pos->frequency = ... 249 + }
+3
Documentation/devicetree/bindings/mfd/mc13xxx.txt
··· 10 10 - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used 11 11 12 12 Sub-nodes: 13 + - codec: Contain the Audio Codec node. 14 + - adc-port: Contain PMIC SSI port number used for ADC. 15 + - dac-port: Contain PMIC SSI port number used for DAC. 13 16 - leds : Contain the led nodes and initial register values in property 14 17 "led-control". Number of register depends of used IC, for MC13783 is 6, 15 18 for MC13892 is 4, for MC34708 is 1. See datasheet for bits definitions of
+5 -4
arch/arm/mach-davinci/da850.c
··· 1092 1092 1093 1093 static int da850_round_armrate(struct clk *clk, unsigned long rate) 1094 1094 { 1095 - int i, ret = 0, diff; 1095 + int ret = 0, diff; 1096 1096 unsigned int best = (unsigned int) -1; 1097 1097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table; 1098 + struct cpufreq_frequency_table *pos; 1098 1099 1099 1100 rate /= 1000; /* convert to kHz */ 1100 1101 1101 - for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 1102 - diff = table[i].frequency - rate; 1102 + cpufreq_for_each_entry(pos, table) { 1103 + diff = pos->frequency - rate; 1103 1104 if (diff < 0) 1104 1105 diff = -diff; 1105 1106 1106 1107 if (diff < best) { 1107 1108 best = diff; 1108 - ret = table[i].frequency; 1109 + ret = pos->frequency; 1109 1110 } 1110 1111 } 1111 1112
-60
arch/arm/mach-omap2/omap_twl.c
··· 46 46 47 47 static bool is_offset_valid; 48 48 static u8 smps_offset; 49 - /* 50 - * Flag to ensure Smartreflex bit in TWL 51 - * being cleared in board file is not overwritten. 52 - */ 53 - static bool __initdata twl_sr_enable_autoinit; 54 49 55 - #define TWL4030_DCDC_GLOBAL_CFG 0x06 56 50 #define REG_SMPS_OFFSET 0xE0 57 - #define SMARTREFLEX_ENABLE BIT(3) 58 51 59 52 static unsigned long twl4030_vsel_to_uv(const u8 vsel) 60 53 { ··· 244 251 if (!cpu_is_omap34xx()) 245 252 return -ENODEV; 246 253 247 - /* 248 - * The smartreflex bit on twl4030 specifies if the setting of voltage 249 - * is done over the I2C_SR path. Since this setting is independent of 250 - * the actual usage of smartreflex AVS module, we enable TWL SR bit 251 - * by default irrespective of whether smartreflex AVS module is enabled 252 - * on the OMAP side or not. This is because without this bit enabled, 253 - * the voltage scaling through vp forceupdate/bypass mechanism of 254 - * voltage scaling will not function on TWL over I2C_SR. 255 - */ 256 - if (!twl_sr_enable_autoinit) 257 - omap3_twl_set_sr_bit(true); 258 - 259 254 voltdm = voltdm_lookup("mpu_iva"); 260 255 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic); 261 256 ··· 251 270 omap_voltage_register_pmic(voltdm, &omap3_core_pmic); 252 271 253 272 return 0; 254 - } 255 - 256 - /** 257 - * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL 258 - * @enable: enable SR mode in twl or not 259 - * 260 - * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure 261 - * voltage scaling through OMAP SR works. Else, the smartreflex bit 262 - * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but 263 - * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct 264 - * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages, 265 - * in those scenarios this bit is to be cleared (enable = false). 266 - * 267 - * Returns 0 on success, error is returned if I2C read/write fails. 268 - */ 269 - int __init omap3_twl_set_sr_bit(bool enable) 270 - { 271 - u8 temp; 272 - int ret; 273 - if (twl_sr_enable_autoinit) 274 - pr_warning("%s: unexpected multiple calls\n", __func__); 275 - 276 - ret = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &temp, 277 - TWL4030_DCDC_GLOBAL_CFG); 278 - if (ret) 279 - goto err; 280 - 281 - if (enable) 282 - temp |= SMARTREFLEX_ENABLE; 283 - else 284 - temp &= ~SMARTREFLEX_ENABLE; 285 - 286 - ret = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, temp, 287 - TWL4030_DCDC_GLOBAL_CFG); 288 - if (!ret) { 289 - twl_sr_enable_autoinit = true; 290 - return 0; 291 - } 292 - err: 293 - pr_err("%s: Error access to TWL4030 (%d)\n", __func__, ret); 294 - return ret; 295 273 }
+4 -5
drivers/cpufreq/acpi-cpufreq.c
··· 213 213 214 214 static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) 215 215 { 216 - int i; 216 + struct cpufreq_frequency_table *pos; 217 217 struct acpi_processor_performance *perf; 218 218 219 219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) ··· 223 223 224 224 perf = data->acpi_data; 225 225 226 - for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { 227 - if (msr == perf->states[data->freq_table[i].driver_data].status) 228 - return data->freq_table[i].frequency; 229 - } 226 + cpufreq_for_each_entry(pos, data->freq_table) 227 + if (msr == perf->states[pos->driver_data].status) 228 + return pos->frequency; 230 229 return data->freq_table[0].frequency; 231 230 } 232 231
+8 -8
drivers/cpufreq/arm_big_little.c
··· 226 226 /* get the minimum frequency in the cpufreq_frequency_table */ 227 227 static inline u32 get_table_min(struct cpufreq_frequency_table *table) 228 228 { 229 - int i; 229 + struct cpufreq_frequency_table *pos; 230 230 uint32_t min_freq = ~0; 231 - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 232 - if (table[i].frequency < min_freq) 233 - min_freq = table[i].frequency; 231 + cpufreq_for_each_entry(pos, table) 232 + if (pos->frequency < min_freq) 233 + min_freq = pos->frequency; 234 234 return min_freq; 235 235 } 236 236 237 237 /* get the maximum frequency in the cpufreq_frequency_table */ 238 238 static inline u32 get_table_max(struct cpufreq_frequency_table *table) 239 239 { 240 - int i; 240 + struct cpufreq_frequency_table *pos; 241 241 uint32_t max_freq = 0; 242 - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 243 - if (table[i].frequency > max_freq) 244 - max_freq = table[i].frequency; 242 + cpufreq_for_each_entry(pos, table) 243 + if (pos->frequency > max_freq) 244 + max_freq = pos->frequency; 245 245 return max_freq; 246 246 } 247 247
+11
drivers/cpufreq/cpufreq.c
··· 237 237 } 238 238 EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 239 239 240 + bool cpufreq_next_valid(struct cpufreq_frequency_table **pos) 241 + { 242 + while ((*pos)->frequency != CPUFREQ_TABLE_END) 243 + if ((*pos)->frequency != CPUFREQ_ENTRY_INVALID) 244 + return true; 245 + else 246 + (*pos)++; 247 + return false; 248 + } 249 + EXPORT_SYMBOL_GPL(cpufreq_next_valid); 250 + 240 251 /********************************************************************* 241 252 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 242 253 *********************************************************************/
+8 -16
drivers/cpufreq/cpufreq_stats.c
··· 182 182 183 183 static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) 184 184 { 185 - unsigned int i, j, count = 0, ret = 0; 185 + unsigned int i, count = 0, ret = 0; 186 186 struct cpufreq_stats *stat; 187 187 unsigned int alloc_size; 188 188 unsigned int cpu = policy->cpu; 189 - struct cpufreq_frequency_table *table; 189 + struct cpufreq_frequency_table *pos, *table; 190 190 191 191 table = cpufreq_frequency_get_table(cpu); 192 192 if (unlikely(!table)) ··· 205 205 stat->cpu = cpu; 206 206 per_cpu(cpufreq_stats_table, cpu) = stat; 207 207 208 - for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 209 - unsigned int freq = table[i].frequency; 210 - if (freq == CPUFREQ_ENTRY_INVALID) 211 - continue; 208 + cpufreq_for_each_valid_entry(pos, table) 212 209 count++; 213 - } 214 210 215 211 alloc_size = count * sizeof(int) + count * sizeof(u64); 216 212 ··· 224 228 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS 225 229 stat->trans_table = stat->freq_table + count; 226 230 #endif 227 - j = 0; 228 - for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 229 - unsigned int freq = table[i].frequency; 230 - if (freq == CPUFREQ_ENTRY_INVALID) 231 - continue; 232 - if (freq_table_get_index(stat, freq) == -1) 233 - stat->freq_table[j++] = freq; 234 - } 235 - stat->state_num = j; 231 + i = 0; 232 + cpufreq_for_each_valid_entry(pos, table) 233 + if (freq_table_get_index(stat, pos->frequency) == -1) 234 + stat->freq_table[i++] = pos->frequency; 235 + stat->state_num = i; 236 236 spin_lock(&cpufreq_stats_lock); 237 237 stat->last_time = get_jiffies_64(); 238 238 stat->last_index = freq_table_get_index(stat, policy->cur);
+3 -5
drivers/cpufreq/dbx500-cpufreq.c
··· 45 45 46 46 static int dbx500_cpufreq_probe(struct platform_device *pdev) 47 47 { 48 - int i = 0; 48 + struct cpufreq_frequency_table *pos; 49 49 50 50 freq_table = dev_get_platdata(&pdev->dev); 51 51 if (!freq_table) { ··· 60 60 } 61 61 62 62 pr_info("dbx500-cpufreq: Available frequencies:\n"); 63 - while (freq_table[i].frequency != CPUFREQ_TABLE_END) { 64 - pr_info(" %d Mhz\n", freq_table[i].frequency/1000); 65 - i++; 66 - } 63 + cpufreq_for_each_entry(pos, freq_table) 64 + pr_info(" %d Mhz\n", pos->frequency / 1000); 67 65 68 66 return cpufreq_register_driver(&dbx500_cpufreq_driver); 69 67 }
+4 -5
drivers/cpufreq/elanfreq.c
··· 147 147 static int elanfreq_cpu_init(struct cpufreq_policy *policy) 148 148 { 149 149 struct cpuinfo_x86 *c = &cpu_data(0); 150 - unsigned int i; 150 + struct cpufreq_frequency_table *pos; 151 151 152 152 /* capability check */ 153 153 if ((c->x86_vendor != X86_VENDOR_AMD) || ··· 159 159 max_freq = elanfreq_get_cpu_frequency(0); 160 160 161 161 /* table init */ 162 - for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { 163 - if (elanfreq_table[i].frequency > max_freq) 164 - elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; 165 - } 162 + cpufreq_for_each_entry(pos, elanfreq_table) 163 + if (pos->frequency > max_freq) 164 + pos->frequency = CPUFREQ_ENTRY_INVALID; 166 165 167 166 /* cpuinfo and default policy values */ 168 167 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
+5 -6
drivers/cpufreq/exynos-cpufreq.c
··· 29 29 static int exynos_cpufreq_get_index(unsigned int freq) 30 30 { 31 31 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table; 32 - int index; 32 + struct cpufreq_frequency_table *pos; 33 33 34 - for (index = 0; 35 - freq_table[index].frequency != CPUFREQ_TABLE_END; index++) 36 - if (freq_table[index].frequency == freq) 34 + cpufreq_for_each_entry(pos, freq_table) 35 + if (pos->frequency == freq) 37 36 break; 38 37 39 - if (freq_table[index].frequency == CPUFREQ_TABLE_END) 38 + if (pos->frequency == CPUFREQ_TABLE_END) 40 39 return -EINVAL; 41 40 42 - return index; 41 + return pos - freq_table; 43 42 } 44 43 45 44 static int exynos_cpufreq_scale(unsigned int target_freq)
+15 -15
drivers/cpufreq/exynos5440-cpufreq.c
··· 114 114 115 115 static int init_div_table(void) 116 116 { 117 - struct cpufreq_frequency_table *freq_tbl = dvfs_info->freq_table; 117 + struct cpufreq_frequency_table *pos, *freq_tbl = dvfs_info->freq_table; 118 118 unsigned int tmp, clk_div, ema_div, freq, volt_id; 119 - int i = 0; 120 119 struct dev_pm_opp *opp; 121 120 122 121 rcu_read_lock(); 123 - for (i = 0; freq_tbl[i].frequency != CPUFREQ_TABLE_END; i++) { 124 - 122 + cpufreq_for_each_entry(pos, freq_tbl) { 125 123 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev, 126 - freq_tbl[i].frequency * 1000, true); 124 + pos->frequency * 1000, true); 127 125 if (IS_ERR(opp)) { 128 126 rcu_read_unlock(); 129 127 dev_err(dvfs_info->dev, 130 128 "failed to find valid OPP for %u KHZ\n", 131 - freq_tbl[i].frequency); 129 + pos->frequency); 132 130 return PTR_ERR(opp); 133 131 } 134 132 135 - freq = freq_tbl[i].frequency / 1000; /* In MHZ */ 133 + freq = pos->frequency / 1000; /* In MHZ */ 136 134 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK) 137 135 << P0_7_CPUCLKDEV_SHIFT; 138 136 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK) ··· 155 157 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT) 156 158 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT)); 157 159 158 - __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * i); 160 + __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * 161 + (pos - freq_tbl)); 159 162 } 160 163 161 164 rcu_read_unlock(); ··· 165 166 166 167 static void exynos_enable_dvfs(unsigned int cur_frequency) 167 168 { 168 - unsigned int tmp, i, cpu; 169 + unsigned int tmp, cpu; 169 170 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table; 171 + struct cpufreq_frequency_table *pos; 170 172 /* Disable DVFS */ 171 173 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL); 172 174 ··· 182 182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN); 183 183 184 184 /* Set initial performance index */ 185 - for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) 186 - if (freq_table[i].frequency == cur_frequency) 185 + cpufreq_for_each_entry(pos, freq_table) 186 + if (pos->frequency == cur_frequency) 187 187 break; 188 188 189 - if (freq_table[i].frequency == CPUFREQ_TABLE_END) { 189 + if (pos->frequency == CPUFREQ_TABLE_END) { 190 190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n"); 191 191 /* Assign the highest frequency */ 192 - i = 0; 193 - cur_frequency = freq_table[i].frequency; 192 + pos = freq_table; 193 + cur_frequency = pos->frequency; 194 194 } 195 195 196 196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ", ··· 199 199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) { 200 200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 201 201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT); 202 - tmp |= (i << C0_3_PSTATE_NEW_SHIFT); 202 + tmp |= ((pos - freq_table) << C0_3_PSTATE_NEW_SHIFT); 203 203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 204 204 } 205 205
+25 -31
drivers/cpufreq/freq_table.c
··· 21 21 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 22 22 struct cpufreq_frequency_table *table) 23 23 { 24 + struct cpufreq_frequency_table *pos; 24 25 unsigned int min_freq = ~0; 25 26 unsigned int max_freq = 0; 26 - unsigned int i; 27 + unsigned int freq; 27 28 28 - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 29 - unsigned int freq = table[i].frequency; 30 - if (freq == CPUFREQ_ENTRY_INVALID) { 31 - pr_debug("table entry %u is invalid, skipping\n", i); 29 + cpufreq_for_each_valid_entry(pos, table) { 30 + freq = pos->frequency; 32 31 33 - continue; 34 - } 35 32 if (!cpufreq_boost_enabled() 36 - && (table[i].flags & CPUFREQ_BOOST_FREQ)) 33 + && (pos->flags & CPUFREQ_BOOST_FREQ)) 37 34 continue; 38 35 39 - pr_debug("table entry %u: %u kHz\n", i, freq); 36 + pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq); 40 37 if (freq < min_freq) 41 38 min_freq = freq; 42 39 if (freq > max_freq) ··· 54 57 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, 55 58 struct cpufreq_frequency_table *table) 56 59 { 57 - unsigned int next_larger = ~0, freq, i = 0; 60 + struct cpufreq_frequency_table *pos; 61 + unsigned int freq, next_larger = ~0; 58 62 bool found = false; 59 63 60 64 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", ··· 63 65 64 66 cpufreq_verify_within_cpu_limits(policy); 65 67 66 - for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) { 67 - if (freq == CPUFREQ_ENTRY_INVALID) 68 - continue; 68 + cpufreq_for_each_valid_entry(pos, table) { 69 + freq = pos->frequency; 70 + 69 71 if ((freq >= policy->min) && (freq <= policy->max)) { 70 72 found = true; 71 73 break; ··· 116 118 .driver_data = ~0, 117 119 .frequency = 0, 118 120 }; 119 - unsigned int i; 121 + struct cpufreq_frequency_table *pos; 122 + unsigned int freq, i = 0; 120 123 121 124 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", 122 125 target_freq, relation, policy->cpu); ··· 131 132 break; 132 133 } 133 134 134 - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 135 - unsigned int freq = table[i].frequency; 136 - if (freq == CPUFREQ_ENTRY_INVALID) 137 - continue; 135 + cpufreq_for_each_valid_entry(pos, table) { 136 + freq = pos->frequency; 137 + 138 + i = pos - table; 138 139 if ((freq < policy->min) || (freq > policy->max)) 139 140 continue; 140 141 switch (relation) { ··· 183 184 int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, 184 185 unsigned int freq) 185 186 { 186 - struct cpufreq_frequency_table *table; 187 - int i; 187 + struct cpufreq_frequency_table *pos, *table; 188 188 189 189 table = cpufreq_frequency_get_table(policy->cpu); 190 190 if (unlikely(!table)) { ··· 191 193 return -ENOENT; 192 194 } 193 195 194 - for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 195 - if (table[i].frequency == freq) 196 - return i; 197 - } 196 + cpufreq_for_each_valid_entry(pos, table) 197 + if (pos->frequency == freq) 198 + return pos - table; 198 199 199 200 return -EINVAL; 200 201 } ··· 205 208 static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, 206 209 bool show_boost) 207 210 { 208 - unsigned int i = 0; 209 211 ssize_t count = 0; 210 - struct cpufreq_frequency_table *table = policy->freq_table; 212 + struct cpufreq_frequency_table *pos, *table = policy->freq_table; 211 213 212 214 if (!table) 213 215 return -ENODEV; 214 216 215 - for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 216 - if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 217 - continue; 217 + cpufreq_for_each_valid_entry(pos, table) { 218 218 /* 219 219 * show_boost = true and driver_data = BOOST freq 220 220 * display BOOST freqs ··· 223 229 * show_boost = false and driver_data != BOOST freq 224 230 * display NON BOOST freqs 225 231 */ 226 - if (show_boost ^ (table[i].flags & CPUFREQ_BOOST_FREQ)) 232 + if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ)) 227 233 continue; 228 234 229 - count += sprintf(&buf[count], "%d ", table[i].frequency); 235 + count += sprintf(&buf[count], "%d ", pos->frequency); 230 236 } 231 237 count += sprintf(&buf[count], "\n"); 232 238
+5 -6
drivers/cpufreq/longhaul.c
··· 530 530 531 531 static void longhaul_setup_voltagescaling(void) 532 532 { 533 + struct cpufreq_frequency_table *freq_pos; 533 534 union msr_longhaul longhaul; 534 535 struct mV_pos minvid, maxvid, vid; 535 536 unsigned int j, speed, pos, kHz_step, numvscales; ··· 609 608 /* Calculate kHz for one voltage step */ 610 609 kHz_step = (highest_speed - min_vid_speed) / numvscales; 611 610 612 - j = 0; 613 - while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { 614 - speed = longhaul_table[j].frequency; 611 + cpufreq_for_each_entry(freq_pos, longhaul_table) { 612 + speed = freq_pos->frequency; 615 613 if (speed > min_vid_speed) 616 614 pos = (speed - min_vid_speed) / kHz_step + minvid.pos; 617 615 else 618 616 pos = minvid.pos; 619 - longhaul_table[j].driver_data |= mV_vrm_table[pos] << 8; 617 + freq_pos->driver_data |= mV_vrm_table[pos] << 8; 620 618 vid = vrm_mV_table[mV_vrm_table[pos]]; 621 619 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", 622 - speed, j, vid.mV); 623 - j++; 620 + speed, (int)(freq_pos - longhaul_table), vid.mV); 624 621 } 625 622 626 623 can_scale_voltage = 1;
+5 -5
drivers/cpufreq/pasemi-cpufreq.c
··· 136 136 137 137 static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) 138 138 { 139 + struct cpufreq_frequency_table *pos; 139 140 const u32 *max_freqp; 140 141 u32 max_freq; 141 - int i, cur_astate; 142 + int cur_astate; 142 143 struct resource res; 143 144 struct device_node *cpu, *dn; 144 145 int err = -ENODEV; ··· 198 197 pr_debug("initializing frequency table\n"); 199 198 200 199 /* initialize frequency table */ 201 - for (i=0; pas_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 202 - pas_freqs[i].frequency = 203 - get_astate_freq(pas_freqs[i].driver_data) * 100000; 204 - pr_debug("%d: %d\n", i, pas_freqs[i].frequency); 200 + cpufreq_for_each_entry(pos, pas_freqs) { 201 + pos->frequency = get_astate_freq(pos->driver_data) * 100000; 202 + pr_debug("%d: %d\n", (int)(pos - pas_freqs), pos->frequency); 205 203 } 206 204 207 205 cur_astate = get_cur_astate(policy->cpu);
+7 -7
drivers/cpufreq/powernow-k6.c
··· 151 151 152 152 static int powernow_k6_cpu_init(struct cpufreq_policy *policy) 153 153 { 154 + struct cpufreq_frequency_table *pos; 154 155 unsigned int i, f; 155 156 unsigned khz; 156 157 ··· 169 168 } 170 169 } 171 170 if (param_max_multiplier) { 172 - for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 173 - if (clock_ratio[i].driver_data == param_max_multiplier) { 171 + cpufreq_for_each_entry(pos, clock_ratio) 172 + if (pos->driver_data == param_max_multiplier) { 174 173 max_multiplier = param_max_multiplier; 175 174 goto have_max_multiplier; 176 175 } 177 - } 178 176 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n"); 179 177 return -EINVAL; 180 178 } ··· 201 201 param_busfreq = busfreq * 10; 202 202 203 203 /* table init */ 204 - for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 205 - f = clock_ratio[i].driver_data; 204 + cpufreq_for_each_entry(pos, clock_ratio) { 205 + f = pos->driver_data; 206 206 if (f > max_multiplier) 207 - clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 207 + pos->frequency = CPUFREQ_ENTRY_INVALID; 208 208 else 209 - clock_ratio[i].frequency = busfreq * f; 209 + pos->frequency = busfreq * f; 210 210 } 211 211 212 212 /* cpuinfo and default policy values */
+5 -4
drivers/cpufreq/ppc_cbe_cpufreq.c
··· 67 67 68 68 static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy) 69 69 { 70 + struct cpufreq_frequency_table *pos; 70 71 const u32 *max_freqp; 71 72 u32 max_freq; 72 - int i, cur_pmode; 73 + int cur_pmode; 73 74 struct device_node *cpu; 74 75 75 76 cpu = of_get_cpu_node(policy->cpu, NULL); ··· 103 102 pr_debug("initializing frequency table\n"); 104 103 105 104 /* initialize frequency table */ 106 - for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 107 - cbe_freqs[i].frequency = max_freq / cbe_freqs[i].driver_data; 108 - pr_debug("%d: %d\n", i, cbe_freqs[i].frequency); 105 + cpufreq_for_each_entry(pos, cbe_freqs) { 106 + pos->frequency = max_freq / pos->driver_data; 107 + pr_debug("%d: %d\n", (int)(pos - cbe_freqs), pos->frequency); 109 108 } 110 109 111 110 /* if DEBUG is enabled set_pmode() measures the latency
+17 -23
drivers/cpufreq/s3c2416-cpufreq.c
··· 266 266 static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq) 267 267 { 268 268 int count, v, i, found; 269 - struct cpufreq_frequency_table *freq; 269 + struct cpufreq_frequency_table *pos; 270 270 struct s3c2416_dvfs *dvfs; 271 271 272 272 count = regulator_count_voltages(s3c_freq->vddarm); ··· 275 275 return; 276 276 } 277 277 278 - freq = s3c_freq->freq_table; 279 - while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 280 - if (freq->frequency == CPUFREQ_ENTRY_INVALID) 281 - continue; 278 + if (!count) 279 + goto out; 282 280 283 - dvfs = &s3c2416_dvfs_table[freq->driver_data]; 281 + cpufreq_for_each_valid_entry(pos, s3c_freq->freq_table) { 282 + dvfs = &s3c2416_dvfs_table[pos->driver_data]; 284 283 found = 0; 285 284 286 285 /* Check only the min-voltage, more is always ok on S3C2416 */ ··· 291 292 292 293 if (!found) { 293 294 pr_debug("cpufreq: %dkHz unsupported by regulator\n", 294 - freq->frequency); 295 - freq->frequency = CPUFREQ_ENTRY_INVALID; 295 + pos->frequency); 296 + pos->frequency = CPUFREQ_ENTRY_INVALID; 296 297 } 297 - 298 - freq++; 299 298 } 300 299 300 + out: 301 301 /* Guessed */ 302 302 s3c_freq->regulator_latency = 1 * 1000 * 1000; 303 303 } ··· 336 338 static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy) 337 339 { 338 340 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq; 339 - struct cpufreq_frequency_table *freq; 341 + struct cpufreq_frequency_table *pos; 340 342 struct clk *msysclk; 341 343 unsigned long rate; 342 344 int ret; ··· 425 427 s3c_freq->regulator_latency = 0; 426 428 #endif 427 429 428 - freq = s3c_freq->freq_table; 429 - while (freq->frequency != CPUFREQ_TABLE_END) { 430 + cpufreq_for_each_entry(pos, s3c_freq->freq_table) { 430 431 /* special handling for dvs mode */ 431 - if (freq->driver_data == 0) { 432 + if (pos->driver_data == 0) { 432 433 if (!s3c_freq->hclk) { 433 434 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n", 434 - freq->frequency); 435 - freq->frequency = CPUFREQ_ENTRY_INVALID; 435 + pos->frequency); 436 + pos->frequency = CPUFREQ_ENTRY_INVALID; 436 437 } else { 437 - freq++; 438 438 continue; 439 439 } 440 440 } 441 441 442 442 /* Check for frequencies we can generate */ 443 443 rate = clk_round_rate(s3c_freq->armdiv, 444 - freq->frequency * 1000); 444 + pos->frequency * 1000); 445 445 rate /= 1000; 446 - if (rate != freq->frequency) { 446 + if (rate != pos->frequency) { 447 447 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n", 448 - freq->frequency, rate); 449 - freq->frequency = CPUFREQ_ENTRY_INVALID; 448 + pos->frequency, rate); 449 + pos->frequency = CPUFREQ_ENTRY_INVALID; 450 450 } 451 - 452 - freq++; 453 451 } 454 452 455 453 /* Datasheet says PLL stabalisation time must be at least 300us,
+5 -10
drivers/cpufreq/s3c64xx-cpufreq.c
··· 118 118 pr_err("Unable to check supported voltages\n"); 119 119 } 120 120 121 - freq = s3c64xx_freq_table; 122 - while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 123 - if (freq->frequency == CPUFREQ_ENTRY_INVALID) 124 - continue; 121 + if (!count) 122 + goto out; 125 123 124 + cpufreq_for_each_valid_entry(freq, s3c64xx_freq_table) { 126 125 dvfs = &s3c64xx_dvfs_table[freq->driver_data]; 127 126 found = 0; 128 127 ··· 136 137 freq->frequency); 137 138 freq->frequency = CPUFREQ_ENTRY_INVALID; 138 139 } 139 - 140 - freq++; 141 140 } 142 141 142 + out: 143 143 /* Guess based on having to do an I2C/SPI write; in future we 144 144 * will be able to query the regulator performance here. */ 145 145 regulator_latency = 1 * 1000 * 1000; ··· 177 179 } 178 180 #endif 179 181 180 - freq = s3c64xx_freq_table; 181 - while (freq->frequency != CPUFREQ_TABLE_END) { 182 + cpufreq_for_each_entry(freq, s3c64xx_freq_table) { 182 183 unsigned long r; 183 184 184 185 /* Check for frequencies we can generate */ ··· 193 196 * frequency is the maximum we can support. */ 194 197 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000) 195 198 freq->frequency = CPUFREQ_ENTRY_INVALID; 196 - 197 - freq++; 198 199 } 199 200 200 201 /* Datasheet says PLL stabalisation time (if we were to use
+2 -2
drivers/extcon/Kconfig
··· 28 28 Say Y here to enable extcon device driver based on ADC values. 29 29 30 30 config EXTCON_MAX14577 31 - tristate "MAX14577 EXTCON Support" 31 + tristate "MAX14577/77836 EXTCON Support" 32 32 depends on MFD_MAX14577 33 33 select IRQ_DOMAIN 34 34 select REGMAP_I2C 35 35 help 36 36 If you say yes here you get support for the MUIC device of 37 - Maxim MAX14577 PMIC. The MAX14577 MUIC is a USB port accessory 37 + Maxim MAX14577/77836. The MAX14577/77836 MUIC is a USB port accessory 38 38 detector and switch. 39 39 40 40 config EXTCON_MAX77693
+128 -48
drivers/extcon/extcon-max14577.c
··· 1 1 /* 2 - * extcon-max14577.c - MAX14577 extcon driver to support MAX14577 MUIC 2 + * extcon-max14577.c - MAX14577/77836 extcon driver to support MUIC 3 3 * 4 - * Copyright (C) 2013 Samsung Electrnoics 4 + * Copyright (C) 2013,2014 Samsung Electrnoics 5 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 + * Krzysztof Kozlowski <k.kozlowski@samsung.com> 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify 8 9 * it under the terms of the GNU General Public License as published by ··· 25 24 #include <linux/mfd/max14577-private.h> 26 25 #include <linux/extcon.h> 27 26 28 - #define DEV_NAME "max14577-muic" 29 27 #define DELAY_MS_DEFAULT 17000 /* unit: millisecond */ 30 28 31 29 enum max14577_muic_adc_debounce_time { ··· 40 40 MAX14577_MUIC_STATUS_END, 41 41 }; 42 42 43 + /** 44 + * struct max14577_muic_irq 45 + * @irq: the index of irq list of MUIC device. 46 + * @name: the name of irq. 47 + * @virq: the virtual irq to use irq domain 48 + */ 49 + struct max14577_muic_irq { 50 + unsigned int irq; 51 + const char *name; 52 + unsigned int virq; 53 + }; 54 + 55 + static struct max14577_muic_irq max14577_muic_irqs[] = { 56 + { MAX14577_IRQ_INT1_ADC, "muic-ADC" }, 57 + { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" }, 58 + { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" }, 59 + { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" }, 60 + { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" }, 61 + { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" }, 62 + { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" }, 63 + { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" }, 64 + }; 65 + 66 + static struct max14577_muic_irq max77836_muic_irqs[] = { 67 + { MAX14577_IRQ_INT1_ADC, "muic-ADC" }, 68 + { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" }, 69 + { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" }, 70 + { MAX77836_IRQ_INT1_ADC1K, "muic-ADC1K" }, 71 + { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" }, 72 + { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" }, 73 + { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" }, 74 + { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" }, 75 + { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" }, 76 + { MAX77836_IRQ_INT2_VIDRM, "muic-VIDRM" }, 77 + }; 78 + 43 79 struct max14577_muic_info { 44 80 struct device *dev; 45 81 struct max14577 *max14577; ··· 84 48 int prev_chg_type; 85 49 u8 status[MAX14577_MUIC_STATUS_END]; 86 50 51 + struct max14577_muic_irq *muic_irqs; 52 + unsigned int muic_irqs_num; 87 53 bool irq_adc; 88 54 bool irq_chg; 89 55 struct work_struct irq_work; ··· 110 72 enum max14577_muic_cable_group { 111 73 MAX14577_CABLE_GROUP_ADC = 0, 112 74 MAX14577_CABLE_GROUP_CHG, 113 - }; 114 - 115 - /** 116 - * struct max14577_muic_irq 117 - * @irq: the index of irq list of MUIC device. 118 - * @name: the name of irq. 119 - * @virq: the virtual irq to use irq domain 120 - */ 121 - struct max14577_muic_irq { 122 - unsigned int irq; 123 - const char *name; 124 - unsigned int virq; 125 - }; 126 - 127 - static struct max14577_muic_irq muic_irqs[] = { 128 - { MAX14577_IRQ_INT1_ADC, "muic-ADC" }, 129 - { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" }, 130 - { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" }, 131 - { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" }, 132 - { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" }, 133 - { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" }, 134 - { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" }, 135 - { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" }, 136 75 }; 137 76 138 77 /* Define supported accessory type */ ··· 543 528 return; 544 529 } 545 530 546 - static irqreturn_t max14577_muic_irq_handler(int irq, void *data) 531 + /* 532 + * Sets irq_adc or irq_chg in max14577_muic_info and returns 1. 533 + * Returns 0 if irq_type does not match registered IRQ for this device type. 534 + */ 535 + static int max14577_parse_irq(struct max14577_muic_info *info, int irq_type) 547 536 { 548 - struct max14577_muic_info *info = data; 549 - int i, irq_type = -1; 550 - 551 - /* 552 - * We may be called multiple times for different nested IRQ-s. 553 - * Including changes in INT1_ADC and INT2_CGHTYP at once. 554 - * However we only need to know whether it was ADC, charger 555 - * or both interrupts so decode IRQ and turn on proper flags. 556 - */ 557 - for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) 558 - if (irq == muic_irqs[i].virq) 559 - irq_type = muic_irqs[i].irq; 560 - 561 537 switch (irq_type) { 562 538 case MAX14577_IRQ_INT1_ADC: 563 539 case MAX14577_IRQ_INT1_ADCLOW: ··· 556 550 /* Handle all of accessory except for 557 551 type of charger accessory */ 558 552 info->irq_adc = true; 559 - break; 553 + return 1; 560 554 case MAX14577_IRQ_INT2_CHGTYP: 561 555 case MAX14577_IRQ_INT2_CHGDETRUN: 562 556 case MAX14577_IRQ_INT2_DCDTMR: ··· 564 558 case MAX14577_IRQ_INT2_VBVOLT: 565 559 /* Handle charger accessory */ 566 560 info->irq_chg = true; 567 - break; 561 + return 1; 568 562 default: 563 + return 0; 564 + } 565 + } 566 + 567 + /* 568 + * Sets irq_adc or irq_chg in max14577_muic_info and returns 1. 569 + * Returns 0 if irq_type does not match registered IRQ for this device type. 570 + */ 571 + static int max77836_parse_irq(struct max14577_muic_info *info, int irq_type) 572 + { 573 + /* First check common max14577 interrupts */ 574 + if (max14577_parse_irq(info, irq_type)) 575 + return 1; 576 + 577 + switch (irq_type) { 578 + case MAX77836_IRQ_INT1_ADC1K: 579 + info->irq_adc = true; 580 + return 1; 581 + case MAX77836_IRQ_INT2_VIDRM: 582 + /* Handle charger accessory */ 583 + info->irq_chg = true; 584 + return 1; 585 + default: 586 + return 0; 587 + } 588 + } 589 + 590 + static irqreturn_t max14577_muic_irq_handler(int irq, void *data) 591 + { 592 + struct max14577_muic_info *info = data; 593 + int i, irq_type = -1; 594 + bool irq_parsed; 595 + 596 + /* 597 + * We may be called multiple times for different nested IRQ-s. 598 + * Including changes in INT1_ADC and INT2_CGHTYP at once. 599 + * However we only need to know whether it was ADC, charger 600 + * or both interrupts so decode IRQ and turn on proper flags. 601 + */ 602 + for (i = 0; i < info->muic_irqs_num; i++) 603 + if (irq == info->muic_irqs[i].virq) 604 + irq_type = info->muic_irqs[i].irq; 605 + 606 + switch (info->max14577->dev_type) { 607 + case MAXIM_DEVICE_TYPE_MAX77836: 608 + irq_parsed = max77836_parse_irq(info, irq_type); 609 + break; 610 + case MAXIM_DEVICE_TYPE_MAX14577: 611 + default: 612 + irq_parsed = max14577_parse_irq(info, irq_type); 613 + break; 614 + } 615 + 616 + if (!irq_parsed) { 569 617 dev_err(info->dev, "muic interrupt: irq %d occurred, skipped\n", 570 618 irq_type); 571 619 return IRQ_HANDLED; ··· 704 644 705 645 INIT_WORK(&info->irq_work, max14577_muic_irq_work); 706 646 647 + switch (max14577->dev_type) { 648 + case MAXIM_DEVICE_TYPE_MAX77836: 649 + info->muic_irqs = max77836_muic_irqs; 650 + info->muic_irqs_num = ARRAY_SIZE(max77836_muic_irqs); 651 + break; 652 + case MAXIM_DEVICE_TYPE_MAX14577: 653 + default: 654 + info->muic_irqs = max14577_muic_irqs; 655 + info->muic_irqs_num = ARRAY_SIZE(max14577_muic_irqs); 656 + } 657 + 707 658 /* Support irq domain for max14577 MUIC device */ 708 - for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) { 709 - struct max14577_muic_irq *muic_irq = &muic_irqs[i]; 659 + for (i = 0; i < info->muic_irqs_num; i++) { 660 + struct max14577_muic_irq *muic_irq = &info->muic_irqs[i]; 710 661 unsigned int virq = 0; 711 662 712 663 virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq); ··· 744 673 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); 745 674 return -ENOMEM; 746 675 } 747 - info->edev->name = DEV_NAME; 676 + 677 + info->edev->name = dev_name(&pdev->dev); 748 678 info->edev->supported_cable = max14577_extcon_cable; 749 679 ret = extcon_dev_register(info->edev); 750 680 if (ret) { ··· 807 735 return 0; 808 736 } 809 737 738 + static const struct platform_device_id max14577_muic_id[] = { 739 + { "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, }, 740 + { "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, }, 741 + { } 742 + }; 743 + MODULE_DEVICE_TABLE(platform, max14577_muic_id); 744 + 810 745 static struct platform_driver max14577_muic_driver = { 811 746 .driver = { 812 - .name = DEV_NAME, 747 + .name = "max14577-muic", 813 748 .owner = THIS_MODULE, 814 749 }, 815 750 .probe = max14577_muic_probe, 816 751 .remove = max14577_muic_remove, 752 + .id_table = max14577_muic_id, 817 753 }; 818 754 819 755 module_platform_driver(max14577_muic_driver); 820 756 821 - MODULE_DESCRIPTION("MAXIM 14577 Extcon driver"); 822 - MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); 757 + MODULE_DESCRIPTION("Maxim 14577/77836 Extcon driver"); 758 + MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 823 759 MODULE_LICENSE("GPL"); 824 760 MODULE_ALIAS("platform:extcon-max14577");
+5 -13
drivers/gpio/gpio-stmpe.c
··· 23 23 enum { REG_RE, REG_FE, REG_IE }; 24 24 25 25 #define CACHE_NR_REGS 3 26 - #define CACHE_NR_BANKS (STMPE_NR_GPIOS / 8) 26 + /* No variant has more than 24 GPIOs */ 27 + #define CACHE_NR_BANKS (24 / 8) 27 28 28 29 struct stmpe_gpio { 29 30 struct gpio_chip chip; ··· 32 31 struct device *dev; 33 32 struct mutex irq_lock; 34 33 struct irq_domain *domain; 35 - 36 - int irq_base; 37 34 unsigned norequest_mask; 38 35 39 36 /* Caches of interrupt control registers for bus_lock */ ··· 310 311 static int stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio, 311 312 struct device_node *np) 312 313 { 313 - int base = 0; 314 - 315 - if (!np) 316 - base = stmpe_gpio->irq_base; 317 - 318 314 stmpe_gpio->domain = irq_domain_add_simple(np, 319 - stmpe_gpio->chip.ngpio, base, 315 + stmpe_gpio->chip.ngpio, 0, 320 316 &stmpe_gpio_irq_simple_ops, stmpe_gpio); 321 317 if (!stmpe_gpio->domain) { 322 318 dev_err(stmpe_gpio->dev, "failed to create irqdomain\n"); ··· 348 354 #ifdef CONFIG_OF 349 355 stmpe_gpio->chip.of_node = np; 350 356 #endif 351 - stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1; 357 + stmpe_gpio->chip.base = -1; 352 358 353 359 if (pdata) 354 360 stmpe_gpio->norequest_mask = pdata->norequest_mask; ··· 356 362 of_property_read_u32(np, "st,norequest-mask", 357 363 &stmpe_gpio->norequest_mask); 358 364 359 - if (irq >= 0) 360 - stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0); 361 - else 365 + if (irq < 0) 362 366 dev_info(&pdev->dev, 363 367 "device configured in no-irq mode; " 364 368 "irqs are not available\n");
+10
drivers/memstick/host/Kconfig
··· 52 52 53 53 To compile this driver as a module, choose M here: the module will 54 54 be called rtsx_pci_ms. 55 + 56 + config MEMSTICK_REALTEK_USB 57 + tristate "Realtek USB Memstick Card Interface Driver" 58 + depends on MFD_RTSX_USB 59 + help 60 + Say Y here to include driver code to support Memstick card interface 61 + of Realtek RTS5129/39 series USB card reader 62 + 63 + To compile this driver as a module, choose M here: the module will 64 + be called rts5139_ms.
+1
drivers/memstick/host/Makefile
··· 6 6 obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o 7 7 obj-$(CONFIG_MEMSTICK_R592) += r592.o 8 8 obj-$(CONFIG_MEMSTICK_REALTEK_PCI) += rtsx_pci_ms.o 9 + obj-$(CONFIG_MEMSTICK_REALTEK_USB) += rtsx_usb_ms.o
+839
drivers/memstick/host/rtsx_usb_ms.c
··· 1 + /* Realtek USB Memstick Card Interface driver 2 + * 3 + * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms of the GNU General Public License version 2 7 + * as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License along 15 + * with this program; if not, see <http://www.gnu.org/licenses/>. 16 + * 17 + * Author: 18 + * Roger Tseng <rogerable@realtek.com> 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/highmem.h> 23 + #include <linux/delay.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/workqueue.h> 26 + #include <linux/memstick.h> 27 + #include <linux/kthread.h> 28 + #include <linux/mfd/rtsx_usb.h> 29 + #include <linux/pm_runtime.h> 30 + #include <linux/mutex.h> 31 + #include <linux/sched.h> 32 + #include <linux/completion.h> 33 + #include <asm/unaligned.h> 34 + 35 + struct rtsx_usb_ms { 36 + struct platform_device *pdev; 37 + struct rtsx_ucr *ucr; 38 + struct memstick_host *msh; 39 + struct memstick_request *req; 40 + 41 + struct mutex host_mutex; 42 + struct work_struct handle_req; 43 + 44 + struct task_struct *detect_ms; 45 + struct completion detect_ms_exit; 46 + 47 + u8 ssc_depth; 48 + unsigned int clock; 49 + int power_mode; 50 + unsigned char ifmode; 51 + bool eject; 52 + }; 53 + 54 + static inline struct device *ms_dev(struct rtsx_usb_ms *host) 55 + { 56 + return &(host->pdev->dev); 57 + } 58 + 59 + static inline void ms_clear_error(struct rtsx_usb_ms *host) 60 + { 61 + struct rtsx_ucr *ucr = host->ucr; 62 + rtsx_usb_ep0_write_register(ucr, CARD_STOP, 63 + MS_STOP | MS_CLR_ERR, 64 + MS_STOP | MS_CLR_ERR); 65 + 66 + rtsx_usb_clear_dma_err(ucr); 67 + rtsx_usb_clear_fsm_err(ucr); 68 + } 69 + 70 + #ifdef DEBUG 71 + 72 + static void ms_print_debug_regs(struct rtsx_usb_ms *host) 73 + { 74 + struct rtsx_ucr *ucr = host->ucr; 75 + u16 i; 76 + u8 *ptr; 77 + 78 + /* Print MS host internal registers */ 79 + rtsx_usb_init_cmd(ucr); 80 + 81 + /* MS_CFG to MS_INT_REG */ 82 + for (i = 0xFD40; i <= 0xFD44; i++) 83 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); 84 + 85 + /* CARD_SHARE_MODE to CARD_GPIO */ 86 + for (i = 0xFD51; i <= 0xFD56; i++) 87 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); 88 + 89 + /* CARD_PULL_CTLx */ 90 + for (i = 0xFD60; i <= 0xFD65; i++) 91 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, i, 0, 0); 92 + 93 + /* CARD_DATA_SOURCE, CARD_SELECT, CARD_CLK_EN, CARD_PWR_CTL */ 94 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_DATA_SOURCE, 0, 0); 95 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_SELECT, 0, 0); 96 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_CLK_EN, 0, 0); 97 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, CARD_PWR_CTL, 0, 0); 98 + 99 + rtsx_usb_send_cmd(ucr, MODE_CR, 100); 100 + rtsx_usb_get_rsp(ucr, 21, 100); 101 + 102 + ptr = ucr->rsp_buf; 103 + for (i = 0xFD40; i <= 0xFD44; i++) 104 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); 105 + for (i = 0xFD51; i <= 0xFD56; i++) 106 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); 107 + for (i = 0xFD60; i <= 0xFD65; i++) 108 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", i, *(ptr++)); 109 + 110 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_DATA_SOURCE, *(ptr++)); 111 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_SELECT, *(ptr++)); 112 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_CLK_EN, *(ptr++)); 113 + dev_dbg(ms_dev(host), "0x%04X: 0x%02x\n", CARD_PWR_CTL, *(ptr++)); 114 + } 115 + 116 + #else 117 + 118 + static void ms_print_debug_regs(struct rtsx_usb_ms *host) 119 + { 120 + } 121 + 122 + #endif 123 + 124 + static int ms_pull_ctl_disable_lqfp48(struct rtsx_ucr *ucr) 125 + { 126 + rtsx_usb_init_cmd(ucr); 127 + 128 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x55); 129 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 130 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 131 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 132 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); 133 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0xA5); 134 + 135 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 136 + } 137 + 138 + static int ms_pull_ctl_disable_qfn24(struct rtsx_ucr *ucr) 139 + { 140 + rtsx_usb_init_cmd(ucr); 141 + 142 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x65); 143 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 144 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 145 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 146 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x56); 147 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0x59); 148 + 149 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 150 + } 151 + 152 + static int ms_pull_ctl_enable_lqfp48(struct rtsx_ucr *ucr) 153 + { 154 + rtsx_usb_init_cmd(ucr); 155 + 156 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x55); 157 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 158 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 159 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 160 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); 161 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0xA5); 162 + 163 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 164 + } 165 + 166 + static int ms_pull_ctl_enable_qfn24(struct rtsx_ucr *ucr) 167 + { 168 + rtsx_usb_init_cmd(ucr); 169 + 170 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x65); 171 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 172 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 173 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 174 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); 175 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0x59); 176 + 177 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 178 + } 179 + 180 + static int ms_power_on(struct rtsx_usb_ms *host) 181 + { 182 + struct rtsx_ucr *ucr = host->ucr; 183 + int err; 184 + 185 + dev_dbg(ms_dev(host), "%s\n", __func__); 186 + 187 + rtsx_usb_init_cmd(ucr); 188 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_SELECT, 0x07, MS_MOD_SEL); 189 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_SHARE_MODE, 190 + CARD_SHARE_MASK, CARD_SHARE_MS); 191 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_EN, 192 + MS_CLK_EN, MS_CLK_EN); 193 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 194 + if (err < 0) 195 + return err; 196 + 197 + if (CHECK_PKG(ucr, LQFP48)) 198 + err = ms_pull_ctl_enable_lqfp48(ucr); 199 + else 200 + err = ms_pull_ctl_enable_qfn24(ucr); 201 + if (err < 0) 202 + return err; 203 + 204 + err = rtsx_usb_write_register(ucr, CARD_PWR_CTL, 205 + POWER_MASK, PARTIAL_POWER_ON); 206 + if (err) 207 + return err; 208 + 209 + usleep_range(800, 1000); 210 + 211 + rtsx_usb_init_cmd(ucr); 212 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL, 213 + POWER_MASK, POWER_ON); 214 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_OE, 215 + MS_OUTPUT_EN, MS_OUTPUT_EN); 216 + 217 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 218 + } 219 + 220 + static int ms_power_off(struct rtsx_usb_ms *host) 221 + { 222 + struct rtsx_ucr *ucr = host->ucr; 223 + int err; 224 + 225 + dev_dbg(ms_dev(host), "%s\n", __func__); 226 + 227 + rtsx_usb_init_cmd(ucr); 228 + 229 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_EN, MS_CLK_EN, 0); 230 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_OE, MS_OUTPUT_EN, 0); 231 + 232 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 233 + if (err < 0) 234 + return err; 235 + 236 + if (CHECK_PKG(ucr, LQFP48)) 237 + return ms_pull_ctl_disable_lqfp48(ucr); 238 + 239 + return ms_pull_ctl_disable_qfn24(ucr); 240 + } 241 + 242 + static int ms_transfer_data(struct rtsx_usb_ms *host, unsigned char data_dir, 243 + u8 tpc, u8 cfg, struct scatterlist *sg) 244 + { 245 + struct rtsx_ucr *ucr = host->ucr; 246 + int err; 247 + unsigned int length = sg->length; 248 + u16 sec_cnt = (u16)(length / 512); 249 + u8 trans_mode, dma_dir, flag; 250 + unsigned int pipe; 251 + struct memstick_dev *card = host->msh->card; 252 + 253 + dev_dbg(ms_dev(host), "%s: tpc = 0x%02x, data_dir = %s, length = %d\n", 254 + __func__, tpc, (data_dir == READ) ? "READ" : "WRITE", 255 + length); 256 + 257 + if (data_dir == READ) { 258 + flag = MODE_CDIR; 259 + dma_dir = DMA_DIR_FROM_CARD; 260 + if (card->id.type != MEMSTICK_TYPE_PRO) 261 + trans_mode = MS_TM_NORMAL_READ; 262 + else 263 + trans_mode = MS_TM_AUTO_READ; 264 + pipe = usb_rcvbulkpipe(ucr->pusb_dev, EP_BULK_IN); 265 + } else { 266 + flag = MODE_CDOR; 267 + dma_dir = DMA_DIR_TO_CARD; 268 + if (card->id.type != MEMSTICK_TYPE_PRO) 269 + trans_mode = MS_TM_NORMAL_WRITE; 270 + else 271 + trans_mode = MS_TM_AUTO_WRITE; 272 + pipe = usb_sndbulkpipe(ucr->pusb_dev, EP_BULK_OUT); 273 + } 274 + 275 + rtsx_usb_init_cmd(ucr); 276 + 277 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc); 278 + if (card->id.type == MEMSTICK_TYPE_PRO) { 279 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_SECTOR_CNT_H, 280 + 0xFF, (u8)(sec_cnt >> 8)); 281 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_SECTOR_CNT_L, 282 + 0xFF, (u8)sec_cnt); 283 + } 284 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg); 285 + 286 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC3, 287 + 0xFF, (u8)(length >> 24)); 288 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC2, 289 + 0xFF, (u8)(length >> 16)); 290 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC1, 291 + 0xFF, (u8)(length >> 8)); 292 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC0, 0xFF, 293 + (u8)length); 294 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_CTL, 295 + 0x03 | DMA_PACK_SIZE_MASK, dma_dir | DMA_EN | DMA_512); 296 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_DATA_SOURCE, 297 + 0x01, RING_BUFFER); 298 + 299 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANSFER, 300 + 0xFF, MS_TRANSFER_START | trans_mode); 301 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, MS_TRANSFER, 302 + MS_TRANSFER_END, MS_TRANSFER_END); 303 + 304 + err = rtsx_usb_send_cmd(ucr, flag | STAGE_MS_STATUS, 100); 305 + if (err) 306 + return err; 307 + 308 + err = rtsx_usb_transfer_data(ucr, pipe, sg, length, 309 + 1, NULL, 10000); 310 + if (err) 311 + goto err_out; 312 + 313 + err = rtsx_usb_get_rsp(ucr, 3, 15000); 314 + if (err) 315 + goto err_out; 316 + 317 + if (ucr->rsp_buf[0] & MS_TRANSFER_ERR || 318 + ucr->rsp_buf[1] & (MS_CRC16_ERR | MS_RDY_TIMEOUT)) { 319 + err = -EIO; 320 + goto err_out; 321 + } 322 + return 0; 323 + err_out: 324 + ms_clear_error(host); 325 + return err; 326 + } 327 + 328 + static int ms_write_bytes(struct rtsx_usb_ms *host, u8 tpc, 329 + u8 cfg, u8 cnt, u8 *data, u8 *int_reg) 330 + { 331 + struct rtsx_ucr *ucr = host->ucr; 332 + int err, i; 333 + 334 + dev_dbg(ms_dev(host), "%s: tpc = 0x%02x\n", __func__, tpc); 335 + 336 + rtsx_usb_init_cmd(ucr); 337 + 338 + for (i = 0; i < cnt; i++) 339 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 340 + PPBUF_BASE2 + i, 0xFF, data[i]); 341 + 342 + if (cnt % 2) 343 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 344 + PPBUF_BASE2 + i, 0xFF, 0xFF); 345 + 346 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc); 347 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_BYTE_CNT, 0xFF, cnt); 348 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg); 349 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_DATA_SOURCE, 350 + 0x01, PINGPONG_BUFFER); 351 + 352 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANSFER, 353 + 0xFF, MS_TRANSFER_START | MS_TM_WRITE_BYTES); 354 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, MS_TRANSFER, 355 + MS_TRANSFER_END, MS_TRANSFER_END); 356 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, MS_TRANS_CFG, 0, 0); 357 + 358 + err = rtsx_usb_send_cmd(ucr, MODE_CR, 100); 359 + if (err) 360 + return err; 361 + 362 + err = rtsx_usb_get_rsp(ucr, 2, 5000); 363 + if (err || (ucr->rsp_buf[0] & MS_TRANSFER_ERR)) { 364 + u8 val; 365 + 366 + rtsx_usb_ep0_read_register(ucr, MS_TRANS_CFG, &val); 367 + dev_dbg(ms_dev(host), "MS_TRANS_CFG: 0x%02x\n", val); 368 + 369 + if (int_reg) 370 + *int_reg = val & 0x0F; 371 + 372 + ms_print_debug_regs(host); 373 + 374 + ms_clear_error(host); 375 + 376 + if (!(tpc & 0x08)) { 377 + if (val & MS_CRC16_ERR) 378 + return -EIO; 379 + } else { 380 + if (!(val & 0x80)) { 381 + if (val & (MS_INT_ERR | MS_INT_CMDNK)) 382 + return -EIO; 383 + } 384 + } 385 + 386 + return -ETIMEDOUT; 387 + } 388 + 389 + if (int_reg) 390 + *int_reg = ucr->rsp_buf[1] & 0x0F; 391 + 392 + return 0; 393 + } 394 + 395 + static int ms_read_bytes(struct rtsx_usb_ms *host, u8 tpc, 396 + u8 cfg, u8 cnt, u8 *data, u8 *int_reg) 397 + { 398 + struct rtsx_ucr *ucr = host->ucr; 399 + int err, i; 400 + u8 *ptr; 401 + 402 + dev_dbg(ms_dev(host), "%s: tpc = 0x%02x\n", __func__, tpc); 403 + 404 + rtsx_usb_init_cmd(ucr); 405 + 406 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TPC, 0xFF, tpc); 407 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_BYTE_CNT, 0xFF, cnt); 408 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANS_CFG, 0xFF, cfg); 409 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_DATA_SOURCE, 410 + 0x01, PINGPONG_BUFFER); 411 + 412 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MS_TRANSFER, 413 + 0xFF, MS_TRANSFER_START | MS_TM_READ_BYTES); 414 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, MS_TRANSFER, 415 + MS_TRANSFER_END, MS_TRANSFER_END); 416 + for (i = 0; i < cnt - 1; i++) 417 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, PPBUF_BASE2 + i, 0, 0); 418 + if (cnt % 2) 419 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, PPBUF_BASE2 + cnt, 0, 0); 420 + else 421 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, 422 + PPBUF_BASE2 + cnt - 1, 0, 0); 423 + 424 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, MS_TRANS_CFG, 0, 0); 425 + 426 + err = rtsx_usb_send_cmd(ucr, MODE_CR, 100); 427 + if (err) 428 + return err; 429 + 430 + err = rtsx_usb_get_rsp(ucr, cnt + 2, 5000); 431 + if (err || (ucr->rsp_buf[0] & MS_TRANSFER_ERR)) { 432 + u8 val; 433 + 434 + rtsx_usb_ep0_read_register(ucr, MS_TRANS_CFG, &val); 435 + dev_dbg(ms_dev(host), "MS_TRANS_CFG: 0x%02x\n", val); 436 + 437 + if (int_reg && (host->ifmode != MEMSTICK_SERIAL)) 438 + *int_reg = val & 0x0F; 439 + 440 + ms_print_debug_regs(host); 441 + 442 + ms_clear_error(host); 443 + 444 + if (!(tpc & 0x08)) { 445 + if (val & MS_CRC16_ERR) 446 + return -EIO; 447 + } else { 448 + if (!(val & 0x80)) { 449 + if (val & (MS_INT_ERR | MS_INT_CMDNK)) 450 + return -EIO; 451 + } 452 + } 453 + 454 + return -ETIMEDOUT; 455 + } 456 + 457 + ptr = ucr->rsp_buf + 1; 458 + for (i = 0; i < cnt; i++) 459 + data[i] = *ptr++; 460 + 461 + 462 + if (int_reg && (host->ifmode != MEMSTICK_SERIAL)) 463 + *int_reg = *ptr & 0x0F; 464 + 465 + return 0; 466 + } 467 + 468 + static int rtsx_usb_ms_issue_cmd(struct rtsx_usb_ms *host) 469 + { 470 + struct memstick_request *req = host->req; 471 + int err = 0; 472 + u8 cfg = 0, int_reg; 473 + 474 + dev_dbg(ms_dev(host), "%s\n", __func__); 475 + 476 + if (req->need_card_int) { 477 + if (host->ifmode != MEMSTICK_SERIAL) 478 + cfg = WAIT_INT; 479 + } 480 + 481 + if (req->long_data) { 482 + err = ms_transfer_data(host, req->data_dir, 483 + req->tpc, cfg, &(req->sg)); 484 + } else { 485 + if (req->data_dir == READ) 486 + err = ms_read_bytes(host, req->tpc, cfg, 487 + req->data_len, req->data, &int_reg); 488 + else 489 + err = ms_write_bytes(host, req->tpc, cfg, 490 + req->data_len, req->data, &int_reg); 491 + } 492 + if (err < 0) 493 + return err; 494 + 495 + if (req->need_card_int) { 496 + if (host->ifmode == MEMSTICK_SERIAL) { 497 + err = ms_read_bytes(host, MS_TPC_GET_INT, 498 + NO_WAIT_INT, 1, &req->int_reg, NULL); 499 + if (err < 0) 500 + return err; 501 + } else { 502 + 503 + if (int_reg & MS_INT_CMDNK) 504 + req->int_reg |= MEMSTICK_INT_CMDNAK; 505 + if (int_reg & MS_INT_BREQ) 506 + req->int_reg |= MEMSTICK_INT_BREQ; 507 + if (int_reg & MS_INT_ERR) 508 + req->int_reg |= MEMSTICK_INT_ERR; 509 + if (int_reg & MS_INT_CED) 510 + req->int_reg |= MEMSTICK_INT_CED; 511 + } 512 + dev_dbg(ms_dev(host), "int_reg: 0x%02x\n", req->int_reg); 513 + } 514 + 515 + return 0; 516 + } 517 + 518 + static void rtsx_usb_ms_handle_req(struct work_struct *work) 519 + { 520 + struct rtsx_usb_ms *host = container_of(work, 521 + struct rtsx_usb_ms, handle_req); 522 + struct rtsx_ucr *ucr = host->ucr; 523 + struct memstick_host *msh = host->msh; 524 + int rc; 525 + 526 + if (!host->req) { 527 + do { 528 + rc = memstick_next_req(msh, &host->req); 529 + dev_dbg(ms_dev(host), "next req %d\n", rc); 530 + 531 + if (!rc) { 532 + mutex_lock(&ucr->dev_mutex); 533 + 534 + if (rtsx_usb_card_exclusive_check(ucr, 535 + RTSX_USB_MS_CARD)) 536 + host->req->error = -EIO; 537 + else 538 + host->req->error = 539 + rtsx_usb_ms_issue_cmd(host); 540 + 541 + mutex_unlock(&ucr->dev_mutex); 542 + 543 + dev_dbg(ms_dev(host), "req result %d\n", 544 + host->req->error); 545 + } 546 + } while (!rc); 547 + } 548 + 549 + } 550 + 551 + static void rtsx_usb_ms_request(struct memstick_host *msh) 552 + { 553 + struct rtsx_usb_ms *host = memstick_priv(msh); 554 + 555 + dev_dbg(ms_dev(host), "--> %s\n", __func__); 556 + 557 + if (!host->eject) 558 + schedule_work(&host->handle_req); 559 + } 560 + 561 + static int rtsx_usb_ms_set_param(struct memstick_host *msh, 562 + enum memstick_param param, int value) 563 + { 564 + struct rtsx_usb_ms *host = memstick_priv(msh); 565 + struct rtsx_ucr *ucr = host->ucr; 566 + unsigned int clock = 0; 567 + u8 ssc_depth = 0; 568 + int err; 569 + 570 + dev_dbg(ms_dev(host), "%s: param = %d, value = %d\n", 571 + __func__, param, value); 572 + 573 + mutex_lock(&ucr->dev_mutex); 574 + 575 + err = rtsx_usb_card_exclusive_check(ucr, RTSX_USB_MS_CARD); 576 + if (err) 577 + goto out; 578 + 579 + switch (param) { 580 + case MEMSTICK_POWER: 581 + if (value == host->power_mode) 582 + break; 583 + 584 + if (value == MEMSTICK_POWER_ON) { 585 + pm_runtime_get_sync(ms_dev(host)); 586 + err = ms_power_on(host); 587 + } else if (value == MEMSTICK_POWER_OFF) { 588 + err = ms_power_off(host); 589 + if (host->msh->card) 590 + pm_runtime_put_noidle(ms_dev(host)); 591 + else 592 + pm_runtime_put(ms_dev(host)); 593 + } else 594 + err = -EINVAL; 595 + if (!err) 596 + host->power_mode = value; 597 + break; 598 + 599 + case MEMSTICK_INTERFACE: 600 + if (value == MEMSTICK_SERIAL) { 601 + clock = 19000000; 602 + ssc_depth = SSC_DEPTH_512K; 603 + err = rtsx_usb_write_register(ucr, MS_CFG, 0x5A, 604 + MS_BUS_WIDTH_1 | PUSH_TIME_DEFAULT); 605 + if (err < 0) 606 + break; 607 + } else if (value == MEMSTICK_PAR4) { 608 + clock = 39000000; 609 + ssc_depth = SSC_DEPTH_1M; 610 + 611 + err = rtsx_usb_write_register(ucr, MS_CFG, 0x5A, 612 + MS_BUS_WIDTH_4 | PUSH_TIME_ODD | 613 + MS_NO_CHECK_INT); 614 + if (err < 0) 615 + break; 616 + } else { 617 + err = -EINVAL; 618 + break; 619 + } 620 + 621 + err = rtsx_usb_switch_clock(ucr, clock, 622 + ssc_depth, false, true, false); 623 + if (err < 0) { 624 + dev_dbg(ms_dev(host), "switch clock failed\n"); 625 + break; 626 + } 627 + 628 + host->ssc_depth = ssc_depth; 629 + host->clock = clock; 630 + host->ifmode = value; 631 + break; 632 + default: 633 + err = -EINVAL; 634 + break; 635 + } 636 + out: 637 + mutex_unlock(&ucr->dev_mutex); 638 + 639 + /* power-on delay */ 640 + if (param == MEMSTICK_POWER && value == MEMSTICK_POWER_ON) 641 + usleep_range(10000, 12000); 642 + 643 + dev_dbg(ms_dev(host), "%s: return = %d\n", __func__, err); 644 + return err; 645 + } 646 + 647 + #ifdef CONFIG_PM_SLEEP 648 + static int rtsx_usb_ms_suspend(struct device *dev) 649 + { 650 + struct rtsx_usb_ms *host = dev_get_drvdata(dev); 651 + struct memstick_host *msh = host->msh; 652 + 653 + dev_dbg(ms_dev(host), "--> %s\n", __func__); 654 + 655 + memstick_suspend_host(msh); 656 + return 0; 657 + } 658 + 659 + static int rtsx_usb_ms_resume(struct device *dev) 660 + { 661 + struct rtsx_usb_ms *host = dev_get_drvdata(dev); 662 + struct memstick_host *msh = host->msh; 663 + 664 + dev_dbg(ms_dev(host), "--> %s\n", __func__); 665 + 666 + memstick_resume_host(msh); 667 + return 0; 668 + } 669 + #endif /* CONFIG_PM_SLEEP */ 670 + 671 + /* 672 + * Thread function of ms card slot detection. The thread starts right after 673 + * successful host addition. It stops while the driver removal function sets 674 + * host->eject true. 675 + */ 676 + static int rtsx_usb_detect_ms_card(void *__host) 677 + { 678 + struct rtsx_usb_ms *host = (struct rtsx_usb_ms *)__host; 679 + struct rtsx_ucr *ucr = host->ucr; 680 + u8 val = 0; 681 + int err; 682 + 683 + for (;;) { 684 + mutex_lock(&ucr->dev_mutex); 685 + 686 + /* Check pending MS card changes */ 687 + err = rtsx_usb_read_register(ucr, CARD_INT_PEND, &val); 688 + if (err) { 689 + mutex_unlock(&ucr->dev_mutex); 690 + goto poll_again; 691 + } 692 + 693 + /* Clear the pending */ 694 + rtsx_usb_write_register(ucr, CARD_INT_PEND, 695 + XD_INT | MS_INT | SD_INT, 696 + XD_INT | MS_INT | SD_INT); 697 + 698 + mutex_unlock(&ucr->dev_mutex); 699 + 700 + if (val & MS_INT) { 701 + dev_dbg(ms_dev(host), "MS slot change detected\n"); 702 + memstick_detect_change(host->msh); 703 + } 704 + 705 + poll_again: 706 + if (host->eject) 707 + break; 708 + 709 + msleep(1000); 710 + } 711 + 712 + complete(&host->detect_ms_exit); 713 + return 0; 714 + } 715 + 716 + static int rtsx_usb_ms_drv_probe(struct platform_device *pdev) 717 + { 718 + struct memstick_host *msh; 719 + struct rtsx_usb_ms *host; 720 + struct rtsx_ucr *ucr; 721 + int err; 722 + 723 + ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent)); 724 + if (!ucr) 725 + return -ENXIO; 726 + 727 + dev_dbg(&(pdev->dev), 728 + "Realtek USB Memstick controller found\n"); 729 + 730 + msh = memstick_alloc_host(sizeof(*host), &pdev->dev); 731 + if (!msh) 732 + return -ENOMEM; 733 + 734 + host = memstick_priv(msh); 735 + host->ucr = ucr; 736 + host->msh = msh; 737 + host->pdev = pdev; 738 + host->power_mode = MEMSTICK_POWER_OFF; 739 + platform_set_drvdata(pdev, host); 740 + 741 + mutex_init(&host->host_mutex); 742 + INIT_WORK(&host->handle_req, rtsx_usb_ms_handle_req); 743 + 744 + init_completion(&host->detect_ms_exit); 745 + host->detect_ms = kthread_create(rtsx_usb_detect_ms_card, host, 746 + "rtsx_usb_ms_%d", pdev->id); 747 + if (IS_ERR(host->detect_ms)) { 748 + dev_dbg(&(pdev->dev), 749 + "Unable to create polling thread.\n"); 750 + err = PTR_ERR(host->detect_ms); 751 + goto err_out; 752 + } 753 + 754 + msh->request = rtsx_usb_ms_request; 755 + msh->set_param = rtsx_usb_ms_set_param; 756 + msh->caps = MEMSTICK_CAP_PAR4; 757 + 758 + pm_runtime_enable(&pdev->dev); 759 + err = memstick_add_host(msh); 760 + if (err) 761 + goto err_out; 762 + 763 + wake_up_process(host->detect_ms); 764 + return 0; 765 + err_out: 766 + memstick_free_host(msh); 767 + return err; 768 + } 769 + 770 + static int rtsx_usb_ms_drv_remove(struct platform_device *pdev) 771 + { 772 + struct rtsx_usb_ms *host = platform_get_drvdata(pdev); 773 + struct memstick_host *msh; 774 + int err; 775 + 776 + msh = host->msh; 777 + host->eject = true; 778 + cancel_work_sync(&host->handle_req); 779 + 780 + mutex_lock(&host->host_mutex); 781 + if (host->req) { 782 + dev_dbg(&(pdev->dev), 783 + "%s: Controller removed during transfer\n", 784 + dev_name(&msh->dev)); 785 + host->req->error = -ENOMEDIUM; 786 + do { 787 + err = memstick_next_req(msh, &host->req); 788 + if (!err) 789 + host->req->error = -ENOMEDIUM; 790 + } while (!err); 791 + } 792 + mutex_unlock(&host->host_mutex); 793 + 794 + wait_for_completion(&host->detect_ms_exit); 795 + memstick_remove_host(msh); 796 + memstick_free_host(msh); 797 + 798 + /* Balance possible unbalanced usage count 799 + * e.g. unconditional module removal 800 + */ 801 + if (pm_runtime_active(ms_dev(host))) 802 + pm_runtime_put(ms_dev(host)); 803 + 804 + pm_runtime_disable(&pdev->dev); 805 + platform_set_drvdata(pdev, NULL); 806 + 807 + dev_dbg(&(pdev->dev), 808 + ": Realtek USB Memstick controller has been removed\n"); 809 + 810 + return 0; 811 + } 812 + 813 + static SIMPLE_DEV_PM_OPS(rtsx_usb_ms_pm_ops, 814 + rtsx_usb_ms_suspend, rtsx_usb_ms_resume); 815 + 816 + static struct platform_device_id rtsx_usb_ms_ids[] = { 817 + { 818 + .name = "rtsx_usb_ms", 819 + }, { 820 + /* sentinel */ 821 + } 822 + }; 823 + MODULE_DEVICE_TABLE(platform, rtsx_usb_ms_ids); 824 + 825 + static struct platform_driver rtsx_usb_ms_driver = { 826 + .probe = rtsx_usb_ms_drv_probe, 827 + .remove = rtsx_usb_ms_drv_remove, 828 + .id_table = rtsx_usb_ms_ids, 829 + .driver = { 830 + .owner = THIS_MODULE, 831 + .name = "rtsx_usb_ms", 832 + .pm = &rtsx_usb_ms_pm_ops, 833 + }, 834 + }; 835 + module_platform_driver(rtsx_usb_ms_driver); 836 + 837 + MODULE_LICENSE("GPL v2"); 838 + MODULE_AUTHOR("Roger Tseng <rogerable@realtek.com>"); 839 + MODULE_DESCRIPTION("Realtek USB Memstick Card Host Driver");
+4 -3
drivers/mfd/Kconfig
··· 331 331 battery-charger under the corresponding menus. 332 332 333 333 config MFD_MAX14577 334 - bool "Maxim Semiconductor MAX14577 MUIC + Charger Support" 334 + bool "Maxim Semiconductor MAX14577/77836 MUIC + Charger Support" 335 335 depends on I2C=y 336 336 select MFD_CORE 337 337 select REGMAP_I2C 338 338 select REGMAP_IRQ 339 339 select IRQ_DOMAIN 340 340 help 341 - Say yes here to add support for Maxim Semiconductor MAX14577. 342 - This is a Micro-USB IC with Charger controls on chip. 341 + Say yes here to add support for Maxim Semiconductor MAX14577 and 342 + MAX77836 Micro-USB ICs with battery charger. 343 343 This driver provides common support for accessing the device; 344 344 additional drivers must be enabled in order to use the functionality 345 345 of the device. ··· 675 675 config MFD_STMPE 676 676 bool "STMicroelectronics STMPE" 677 677 depends on (I2C=y || SPI_MASTER=y) 678 + depends on OF 678 679 select MFD_CORE 679 680 help 680 681 Support for the STMPE family of I/O Expanders from
+24 -17
drivers/mfd/arizona-core.c
··· 508 508 } 509 509 EXPORT_SYMBOL_GPL(arizona_of_get_type); 510 510 511 + int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop, 512 + bool mandatory) 513 + { 514 + int gpio; 515 + 516 + gpio = of_get_named_gpio(arizona->dev->of_node, prop, 0); 517 + if (gpio < 0) { 518 + if (mandatory) 519 + dev_err(arizona->dev, 520 + "Mandatory DT gpio %s missing/malformed: %d\n", 521 + prop, gpio); 522 + 523 + gpio = 0; 524 + } 525 + 526 + return gpio; 527 + } 528 + EXPORT_SYMBOL_GPL(arizona_of_get_named_gpio); 529 + 511 530 static int arizona_of_get_core_pdata(struct arizona *arizona) 512 531 { 532 + struct arizona_pdata *pdata = &arizona->pdata; 513 533 int ret, i; 514 534 515 - arizona->pdata.reset = of_get_named_gpio(arizona->dev->of_node, 516 - "wlf,reset", 0); 517 - if (arizona->pdata.reset < 0) 518 - arizona->pdata.reset = 0; 519 - 520 - arizona->pdata.ldoena = of_get_named_gpio(arizona->dev->of_node, 521 - "wlf,ldoena", 0); 522 - if (arizona->pdata.ldoena < 0) 523 - arizona->pdata.ldoena = 0; 535 + pdata->reset = arizona_of_get_named_gpio(arizona, "wlf,reset", true); 524 536 525 537 ret = of_property_read_u32_array(arizona->dev->of_node, 526 538 "wlf,gpio-defaults", ··· 663 651 arizona->type); 664 652 return -EINVAL; 665 653 } 654 + 655 + /* Mark DCVDD as external, LDO1 driver will clear if internal */ 656 + arizona->external_dcvdd = true; 666 657 667 658 ret = mfd_add_devices(arizona->dev, -1, early_devs, 668 659 ARRAY_SIZE(early_devs), NULL, 0, NULL); ··· 865 850 regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, 866 851 arizona->pdata.gpio_defaults[i]); 867 852 } 868 - 869 - /* 870 - * LDO1 can only be used to supply DCVDD so if it has no 871 - * consumers then DCVDD is supplied externally. 872 - */ 873 - if (arizona->pdata.ldo1 && 874 - arizona->pdata.ldo1->num_consumer_supplies == 0) 875 - arizona->external_dcvdd = true; 876 853 877 854 pm_runtime_set_autosuspend_delay(arizona->dev, 100); 878 855 pm_runtime_use_autosuspend(arizona->dev);
+8 -11
drivers/mfd/db8500-prcmu.c
··· 1734 1734 1735 1735 static long round_armss_rate(unsigned long rate) 1736 1736 { 1737 + struct cpufreq_frequency_table *pos; 1737 1738 long freq = 0; 1738 - int i = 0; 1739 1739 1740 1740 /* cpufreq table frequencies is in KHz. */ 1741 1741 rate = rate / 1000; 1742 1742 1743 1743 /* Find the corresponding arm opp from the cpufreq table. */ 1744 - while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1745 - freq = db8500_cpufreq_table[i].frequency; 1744 + cpufreq_for_each_entry(pos, db8500_cpufreq_table) { 1745 + freq = pos->frequency; 1746 1746 if (freq == rate) 1747 1747 break; 1748 - i++; 1749 1748 } 1750 1749 1751 1750 /* Return the last valid value, even if a match was not found. */ ··· 1885 1886 1886 1887 static int set_armss_rate(unsigned long rate) 1887 1888 { 1888 - int i = 0; 1889 + struct cpufreq_frequency_table *pos; 1889 1890 1890 1891 /* cpufreq table frequencies is in KHz. */ 1891 1892 rate = rate / 1000; 1892 1893 1893 1894 /* Find the corresponding arm opp from the cpufreq table. */ 1894 - while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1895 - if (db8500_cpufreq_table[i].frequency == rate) 1895 + cpufreq_for_each_entry(pos, db8500_cpufreq_table) 1896 + if (pos->frequency == rate) 1896 1897 break; 1897 - i++; 1898 - } 1899 1898 1900 - if (db8500_cpufreq_table[i].frequency != rate) 1899 + if (pos->frequency != rate) 1901 1900 return -EINVAL; 1902 1901 1903 1902 /* Set the new arm opp. */ 1904 - return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].driver_data); 1903 + return db8500_prcmu_set_arm_opp(pos->driver_data); 1905 1904 } 1906 1905 1907 1906 static int set_plldsi_rate(unsigned long rate)
+272 -43
drivers/mfd/max14577.c
··· 1 1 /* 2 - * max14577.c - mfd core driver for the Maxim 14577 2 + * max14577.c - mfd core driver for the Maxim 14577/77836 3 3 * 4 - * Copyright (C) 2013 Samsung Electrnoics 4 + * Copyright (C) 2014 Samsung Electrnoics 5 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 7 7 * ··· 21 21 #include <linux/err.h> 22 22 #include <linux/module.h> 23 23 #include <linux/interrupt.h> 24 + #include <linux/of_device.h> 24 25 #include <linux/mfd/core.h> 25 26 #include <linux/mfd/max14577.h> 26 27 #include <linux/mfd/max14577-private.h> ··· 38 37 { .name = "max14577-charger", }, 39 38 }; 40 39 41 - static bool max14577_volatile_reg(struct device *dev, unsigned int reg) 40 + static struct mfd_cell max77836_devs[] = { 41 + { 42 + .name = "max77836-muic", 43 + .of_compatible = "maxim,max77836-muic", 44 + }, 45 + { 46 + .name = "max77836-regulator", 47 + .of_compatible = "maxim,max77836-regulator", 48 + }, 49 + { 50 + .name = "max77836-charger", 51 + .of_compatible = "maxim,max77836-charger", 52 + }, 53 + { 54 + .name = "max77836-battery", 55 + .of_compatible = "maxim,max77836-battery", 56 + }, 57 + }; 58 + 59 + static struct of_device_id max14577_dt_match[] = { 60 + { 61 + .compatible = "maxim,max14577", 62 + .data = (void *)MAXIM_DEVICE_TYPE_MAX14577, 63 + }, 64 + { 65 + .compatible = "maxim,max77836", 66 + .data = (void *)MAXIM_DEVICE_TYPE_MAX77836, 67 + }, 68 + {}, 69 + }; 70 + 71 + static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg) 42 72 { 43 73 switch (reg) { 44 74 case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3: ··· 80 48 return false; 81 49 } 82 50 83 - static const struct regmap_config max14577_regmap_config = { 51 + static bool max77836_muic_volatile_reg(struct device *dev, unsigned int reg) 52 + { 53 + /* Any max14577 volatile registers are also max77836 volatile. */ 54 + if (max14577_muic_volatile_reg(dev, reg)) 55 + return true; 56 + 57 + switch (reg) { 58 + case MAX77836_FG_REG_VCELL_MSB ... MAX77836_FG_REG_SOC_LSB: 59 + case MAX77836_FG_REG_CRATE_MSB ... MAX77836_FG_REG_CRATE_LSB: 60 + case MAX77836_FG_REG_STATUS_H ... MAX77836_FG_REG_STATUS_L: 61 + case MAX77836_PMIC_REG_INTSRC: 62 + case MAX77836_PMIC_REG_TOPSYS_INT: 63 + case MAX77836_PMIC_REG_TOPSYS_STAT: 64 + return true; 65 + default: 66 + break; 67 + } 68 + return false; 69 + } 70 + 71 + static const struct regmap_config max14577_muic_regmap_config = { 84 72 .reg_bits = 8, 85 73 .val_bits = 8, 86 - .volatile_reg = max14577_volatile_reg, 74 + .volatile_reg = max14577_muic_volatile_reg, 87 75 .max_register = MAX14577_REG_END, 76 + }; 77 + 78 + static const struct regmap_config max77836_pmic_regmap_config = { 79 + .reg_bits = 8, 80 + .val_bits = 8, 81 + .volatile_reg = max77836_muic_volatile_reg, 82 + .max_register = MAX77836_PMIC_REG_END, 88 83 }; 89 84 90 85 static const struct regmap_irq max14577_irqs[] = { 91 86 /* INT1 interrupts */ 92 - { .reg_offset = 0, .mask = INT1_ADC_MASK, }, 93 - { .reg_offset = 0, .mask = INT1_ADCLOW_MASK, }, 94 - { .reg_offset = 0, .mask = INT1_ADCERR_MASK, }, 87 + { .reg_offset = 0, .mask = MAX14577_INT1_ADC_MASK, }, 88 + { .reg_offset = 0, .mask = MAX14577_INT1_ADCLOW_MASK, }, 89 + { .reg_offset = 0, .mask = MAX14577_INT1_ADCERR_MASK, }, 95 90 /* INT2 interrupts */ 96 - { .reg_offset = 1, .mask = INT2_CHGTYP_MASK, }, 97 - { .reg_offset = 1, .mask = INT2_CHGDETRUN_MASK, }, 98 - { .reg_offset = 1, .mask = INT2_DCDTMR_MASK, }, 99 - { .reg_offset = 1, .mask = INT2_DBCHG_MASK, }, 100 - { .reg_offset = 1, .mask = INT2_VBVOLT_MASK, }, 91 + { .reg_offset = 1, .mask = MAX14577_INT2_CHGTYP_MASK, }, 92 + { .reg_offset = 1, .mask = MAX14577_INT2_CHGDETRUN_MASK, }, 93 + { .reg_offset = 1, .mask = MAX14577_INT2_DCDTMR_MASK, }, 94 + { .reg_offset = 1, .mask = MAX14577_INT2_DBCHG_MASK, }, 95 + { .reg_offset = 1, .mask = MAX14577_INT2_VBVOLT_MASK, }, 101 96 /* INT3 interrupts */ 102 - { .reg_offset = 2, .mask = INT3_EOC_MASK, }, 103 - { .reg_offset = 2, .mask = INT3_CGMBC_MASK, }, 104 - { .reg_offset = 2, .mask = INT3_OVP_MASK, }, 105 - { .reg_offset = 2, .mask = INT3_MBCCHGERR_MASK, }, 97 + { .reg_offset = 2, .mask = MAX14577_INT3_EOC_MASK, }, 98 + { .reg_offset = 2, .mask = MAX14577_INT3_CGMBC_MASK, }, 99 + { .reg_offset = 2, .mask = MAX14577_INT3_OVP_MASK, }, 100 + { .reg_offset = 2, .mask = MAX14577_INT3_MBCCHGERR_MASK, }, 106 101 }; 107 102 108 103 static const struct regmap_irq_chip max14577_irq_chip = { 109 104 .name = "max14577", 110 105 .status_base = MAX14577_REG_INT1, 111 106 .mask_base = MAX14577_REG_INTMASK1, 112 - .mask_invert = 1, 107 + .mask_invert = true, 113 108 .num_regs = 3, 114 109 .irqs = max14577_irqs, 115 110 .num_irqs = ARRAY_SIZE(max14577_irqs), 116 111 }; 112 + 113 + static const struct regmap_irq max77836_muic_irqs[] = { 114 + /* INT1 interrupts */ 115 + { .reg_offset = 0, .mask = MAX14577_INT1_ADC_MASK, }, 116 + { .reg_offset = 0, .mask = MAX14577_INT1_ADCLOW_MASK, }, 117 + { .reg_offset = 0, .mask = MAX14577_INT1_ADCERR_MASK, }, 118 + { .reg_offset = 0, .mask = MAX77836_INT1_ADC1K_MASK, }, 119 + /* INT2 interrupts */ 120 + { .reg_offset = 1, .mask = MAX14577_INT2_CHGTYP_MASK, }, 121 + { .reg_offset = 1, .mask = MAX14577_INT2_CHGDETRUN_MASK, }, 122 + { .reg_offset = 1, .mask = MAX14577_INT2_DCDTMR_MASK, }, 123 + { .reg_offset = 1, .mask = MAX14577_INT2_DBCHG_MASK, }, 124 + { .reg_offset = 1, .mask = MAX14577_INT2_VBVOLT_MASK, }, 125 + { .reg_offset = 1, .mask = MAX77836_INT2_VIDRM_MASK, }, 126 + /* INT3 interrupts */ 127 + { .reg_offset = 2, .mask = MAX14577_INT3_EOC_MASK, }, 128 + { .reg_offset = 2, .mask = MAX14577_INT3_CGMBC_MASK, }, 129 + { .reg_offset = 2, .mask = MAX14577_INT3_OVP_MASK, }, 130 + { .reg_offset = 2, .mask = MAX14577_INT3_MBCCHGERR_MASK, }, 131 + }; 132 + 133 + static const struct regmap_irq_chip max77836_muic_irq_chip = { 134 + .name = "max77836-muic", 135 + .status_base = MAX14577_REG_INT1, 136 + .mask_base = MAX14577_REG_INTMASK1, 137 + .mask_invert = true, 138 + .num_regs = 3, 139 + .irqs = max77836_muic_irqs, 140 + .num_irqs = ARRAY_SIZE(max77836_muic_irqs), 141 + }; 142 + 143 + static const struct regmap_irq max77836_pmic_irqs[] = { 144 + { .reg_offset = 0, .mask = MAX77836_TOPSYS_INT_T120C_MASK, }, 145 + { .reg_offset = 0, .mask = MAX77836_TOPSYS_INT_T140C_MASK, }, 146 + }; 147 + 148 + static const struct regmap_irq_chip max77836_pmic_irq_chip = { 149 + .name = "max77836-pmic", 150 + .status_base = MAX77836_PMIC_REG_TOPSYS_INT, 151 + .mask_base = MAX77836_PMIC_REG_TOPSYS_INT_MASK, 152 + .mask_invert = false, 153 + .num_regs = 1, 154 + .irqs = max77836_pmic_irqs, 155 + .num_irqs = ARRAY_SIZE(max77836_pmic_irqs), 156 + }; 157 + 158 + static void max14577_print_dev_type(struct max14577 *max14577) 159 + { 160 + u8 reg_data, vendor_id, device_id; 161 + int ret; 162 + 163 + ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, 164 + &reg_data); 165 + if (ret) { 166 + dev_err(max14577->dev, 167 + "Failed to read DEVICEID register: %d\n", ret); 168 + return; 169 + } 170 + 171 + vendor_id = ((reg_data & DEVID_VENDORID_MASK) >> 172 + DEVID_VENDORID_SHIFT); 173 + device_id = ((reg_data & DEVID_DEVICEID_MASK) >> 174 + DEVID_DEVICEID_SHIFT); 175 + 176 + dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n", 177 + max14577->dev_type, device_id, vendor_id); 178 + } 179 + 180 + /* 181 + * Max77836 specific initialization code for driver probe. 182 + * Adds new I2C dummy device, regmap and regmap IRQ chip. 183 + * Unmasks Interrupt Source register. 184 + * 185 + * On success returns 0. 186 + * On failure returns errno and reverts any changes done so far (e.g. remove 187 + * I2C dummy device), except masking the INT SRC register. 188 + */ 189 + static int max77836_init(struct max14577 *max14577) 190 + { 191 + int ret; 192 + u8 intsrc_mask; 193 + 194 + max14577->i2c_pmic = i2c_new_dummy(max14577->i2c->adapter, 195 + I2C_ADDR_PMIC); 196 + if (!max14577->i2c_pmic) { 197 + dev_err(max14577->dev, "Failed to register PMIC I2C device\n"); 198 + return -ENODEV; 199 + } 200 + i2c_set_clientdata(max14577->i2c_pmic, max14577); 201 + 202 + max14577->regmap_pmic = devm_regmap_init_i2c(max14577->i2c_pmic, 203 + &max77836_pmic_regmap_config); 204 + if (IS_ERR(max14577->regmap_pmic)) { 205 + ret = PTR_ERR(max14577->regmap_pmic); 206 + dev_err(max14577->dev, "Failed to allocate PMIC register map: %d\n", 207 + ret); 208 + goto err; 209 + } 210 + 211 + /* Un-mask MAX77836 Interrupt Source register */ 212 + ret = max14577_read_reg(max14577->regmap_pmic, 213 + MAX77836_PMIC_REG_INTSRC_MASK, &intsrc_mask); 214 + if (ret < 0) { 215 + dev_err(max14577->dev, "Failed to read PMIC register\n"); 216 + goto err; 217 + } 218 + 219 + intsrc_mask &= ~(MAX77836_INTSRC_MASK_TOP_INT_MASK); 220 + intsrc_mask &= ~(MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK); 221 + ret = max14577_write_reg(max14577->regmap_pmic, 222 + MAX77836_PMIC_REG_INTSRC_MASK, intsrc_mask); 223 + if (ret < 0) { 224 + dev_err(max14577->dev, "Failed to write PMIC register\n"); 225 + goto err; 226 + } 227 + 228 + ret = regmap_add_irq_chip(max14577->regmap_pmic, max14577->irq, 229 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED, 230 + 0, &max77836_pmic_irq_chip, 231 + &max14577->irq_data_pmic); 232 + if (ret != 0) { 233 + dev_err(max14577->dev, "Failed to request PMIC IRQ %d: %d\n", 234 + max14577->irq, ret); 235 + goto err; 236 + } 237 + 238 + return 0; 239 + 240 + err: 241 + i2c_unregister_device(max14577->i2c_pmic); 242 + 243 + return ret; 244 + } 245 + 246 + /* 247 + * Max77836 specific de-initialization code for driver remove. 248 + */ 249 + static void max77836_remove(struct max14577 *max14577) 250 + { 251 + regmap_del_irq_chip(max14577->irq, max14577->irq_data_pmic); 252 + i2c_unregister_device(max14577->i2c_pmic); 253 + } 117 254 118 255 static int max14577_i2c_probe(struct i2c_client *i2c, 119 256 const struct i2c_device_id *id) ··· 290 89 struct max14577 *max14577; 291 90 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); 292 91 struct device_node *np = i2c->dev.of_node; 293 - u8 reg_data; 294 92 int ret = 0; 93 + const struct regmap_irq_chip *irq_chip; 94 + struct mfd_cell *mfd_devs; 95 + unsigned int mfd_devs_size; 96 + int irq_flags; 295 97 296 98 if (np) { 297 99 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); ··· 317 113 max14577->i2c = i2c; 318 114 max14577->irq = i2c->irq; 319 115 320 - max14577->regmap = devm_regmap_init_i2c(i2c, &max14577_regmap_config); 116 + max14577->regmap = devm_regmap_init_i2c(i2c, 117 + &max14577_muic_regmap_config); 321 118 if (IS_ERR(max14577->regmap)) { 322 119 ret = PTR_ERR(max14577->regmap); 323 120 dev_err(max14577->dev, "Failed to allocate register map: %d\n", ··· 326 121 return ret; 327 122 } 328 123 329 - ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, 330 - &reg_data); 331 - if (ret) { 332 - dev_err(max14577->dev, "Device not found on this channel: %d\n", 333 - ret); 334 - return ret; 124 + if (np) { 125 + const struct of_device_id *of_id; 126 + 127 + of_id = of_match_device(max14577_dt_match, &i2c->dev); 128 + if (of_id) 129 + max14577->dev_type = (unsigned int)of_id->data; 130 + } else { 131 + max14577->dev_type = id->driver_data; 335 132 } 336 - max14577->vendor_id = ((reg_data & DEVID_VENDORID_MASK) >> 337 - DEVID_VENDORID_SHIFT); 338 - max14577->device_id = ((reg_data & DEVID_DEVICEID_MASK) >> 339 - DEVID_DEVICEID_SHIFT); 340 - dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n", 341 - max14577->device_id, max14577->vendor_id); 133 + 134 + max14577_print_dev_type(max14577); 135 + 136 + switch (max14577->dev_type) { 137 + case MAXIM_DEVICE_TYPE_MAX77836: 138 + irq_chip = &max77836_muic_irq_chip; 139 + mfd_devs = max77836_devs; 140 + mfd_devs_size = ARRAY_SIZE(max77836_devs); 141 + irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED; 142 + break; 143 + case MAXIM_DEVICE_TYPE_MAX14577: 144 + default: 145 + irq_chip = &max14577_irq_chip; 146 + mfd_devs = max14577_devs; 147 + mfd_devs_size = ARRAY_SIZE(max14577_devs); 148 + irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; 149 + break; 150 + } 342 151 343 152 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, 344 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0, 345 - &max14577_irq_chip, 153 + irq_flags, 0, irq_chip, 346 154 &max14577->irq_data); 347 155 if (ret != 0) { 348 156 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", ··· 363 145 return ret; 364 146 } 365 147 366 - ret = mfd_add_devices(max14577->dev, -1, max14577_devs, 367 - ARRAY_SIZE(max14577_devs), NULL, 0, 148 + /* Max77836 specific initialization code (additional regmap) */ 149 + if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) { 150 + ret = max77836_init(max14577); 151 + if (ret < 0) 152 + goto err_max77836; 153 + } 154 + 155 + ret = mfd_add_devices(max14577->dev, -1, mfd_devs, 156 + mfd_devs_size, NULL, 0, 368 157 regmap_irq_get_domain(max14577->irq_data)); 369 158 if (ret < 0) 370 159 goto err_mfd; ··· 381 156 return 0; 382 157 383 158 err_mfd: 159 + if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) 160 + max77836_remove(max14577); 161 + err_max77836: 384 162 regmap_del_irq_chip(max14577->irq, max14577->irq_data); 385 163 386 164 return ret; ··· 395 167 396 168 mfd_remove_devices(max14577->dev); 397 169 regmap_del_irq_chip(max14577->irq, max14577->irq_data); 170 + if (max14577->dev_type == MAXIM_DEVICE_TYPE_MAX77836) 171 + max77836_remove(max14577); 398 172 399 173 return 0; 400 174 } 401 175 402 176 static const struct i2c_device_id max14577_i2c_id[] = { 403 - { "max14577", 0 }, 177 + { "max14577", MAXIM_DEVICE_TYPE_MAX14577, }, 178 + { "max77836", MAXIM_DEVICE_TYPE_MAX77836, }, 404 179 { } 405 180 }; 406 181 MODULE_DEVICE_TABLE(i2c, max14577_i2c_id); ··· 446 215 } 447 216 #endif /* CONFIG_PM_SLEEP */ 448 217 449 - static struct of_device_id max14577_dt_match[] = { 450 - { .compatible = "maxim,max14577", }, 451 - {}, 452 - }; 453 - 454 218 static SIMPLE_DEV_PM_OPS(max14577_pm, max14577_suspend, max14577_resume); 455 219 456 220 static struct i2c_driver max14577_i2c_driver = { ··· 462 236 463 237 static int __init max14577_i2c_init(void) 464 238 { 239 + BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM); 240 + BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM); 241 + 465 242 return i2c_add_driver(&max14577_i2c_driver); 466 243 } 467 244 subsys_initcall(max14577_i2c_init); ··· 476 247 module_exit(max14577_i2c_exit); 477 248 478 249 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 479 - MODULE_DESCRIPTION("MAXIM 14577 multi-function core driver"); 250 + MODULE_DESCRIPTION("Maxim 14577/77836 multi-function core driver"); 480 251 MODULE_LICENSE("GPL");
+7 -3
drivers/mfd/mc13xxx-core.c
··· 673 673 if (mc13xxx->flags & MC13XXX_USE_ADC) 674 674 mc13xxx_add_subdevice(mc13xxx, "%s-adc"); 675 675 676 - if (mc13xxx->flags & MC13XXX_USE_CODEC) 677 - mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec", 678 - pdata->codec, sizeof(*pdata->codec)); 676 + if (mc13xxx->flags & MC13XXX_USE_CODEC) { 677 + if (pdata) 678 + mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec", 679 + pdata->codec, sizeof(*pdata->codec)); 680 + else 681 + mc13xxx_add_subdevice(mc13xxx, "%s-codec"); 682 + } 679 683 680 684 if (mc13xxx->flags & MC13XXX_USE_RTC) 681 685 mc13xxx_add_subdevice(mc13xxx, "%s-rtc");
+10 -4
drivers/mfd/rtsx_usb.c
··· 67 67 ucr->sg_timer.expires = jiffies + msecs_to_jiffies(timeout); 68 68 add_timer(&ucr->sg_timer); 69 69 usb_sg_wait(&ucr->current_sg); 70 - del_timer(&ucr->sg_timer); 70 + del_timer_sync(&ucr->sg_timer); 71 71 72 72 if (act_len) 73 73 *act_len = ucr->current_sg.bytes; ··· 644 644 if (ret) 645 645 goto out_init_fail; 646 646 647 + /* initialize USB SG transfer timer */ 648 + setup_timer(&ucr->sg_timer, rtsx_usb_sg_timed_out, (unsigned long) ucr); 649 + 647 650 ret = mfd_add_devices(&intf->dev, usb_dev->devnum, rtsx_usb_cells, 648 651 ARRAY_SIZE(rtsx_usb_cells), NULL, 0, NULL); 649 652 if (ret) 650 653 goto out_init_fail; 651 654 652 - /* initialize USB SG transfer timer */ 653 - init_timer(&ucr->sg_timer); 654 - setup_timer(&ucr->sg_timer, rtsx_usb_sg_timed_out, (unsigned long) ucr); 655 655 #ifdef CONFIG_PM 656 656 intf->needs_remote_wakeup = 1; 657 657 usb_enable_autosuspend(usb_dev); ··· 687 687 dev_dbg(&intf->dev, "%s called with pm message 0x%04u\n", 688 688 __func__, message.event); 689 689 690 + /* 691 + * Call to make sure LED is off during suspend to save more power. 692 + * It is NOT a permanent state and could be turned on anytime later. 693 + * Thus no need to call turn_on when resunming. 694 + */ 690 695 mutex_lock(&ucr->dev_mutex); 691 696 rtsx_usb_turn_off_led(ucr); 692 697 mutex_unlock(&ucr->dev_mutex); 698 + 693 699 return 0; 694 700 } 695 701
+29 -1
drivers/mfd/stmpe-i2c.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 16 #include <linux/types.h> 17 + #include <linux/of_device.h> 17 18 #include "stmpe.h" 18 19 19 20 static int i2c_reg_read(struct stmpe *stmpe, u8 reg) ··· 53 52 .write_block = i2c_block_write, 54 53 }; 55 54 55 + static const struct of_device_id stmpe_of_match[] = { 56 + { .compatible = "st,stmpe610", .data = (void *)STMPE610, }, 57 + { .compatible = "st,stmpe801", .data = (void *)STMPE801, }, 58 + { .compatible = "st,stmpe811", .data = (void *)STMPE811, }, 59 + { .compatible = "st,stmpe1601", .data = (void *)STMPE1601, }, 60 + { .compatible = "st,stmpe1801", .data = (void *)STMPE1801, }, 61 + { .compatible = "st,stmpe2401", .data = (void *)STMPE2401, }, 62 + { .compatible = "st,stmpe2403", .data = (void *)STMPE2403, }, 63 + {}, 64 + }; 65 + MODULE_DEVICE_TABLE(of, stmpe_of_match); 66 + 56 67 static int 57 68 stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 58 69 { 70 + int partnum; 71 + const struct of_device_id *of_id; 72 + 59 73 i2c_ci.data = (void *)id; 60 74 i2c_ci.irq = i2c->irq; 61 75 i2c_ci.client = i2c; 62 76 i2c_ci.dev = &i2c->dev; 63 77 64 - return stmpe_probe(&i2c_ci, id->driver_data); 78 + of_id = of_match_device(stmpe_of_match, &i2c->dev); 79 + if (!of_id) { 80 + /* 81 + * This happens when the I2C ID matches the node name 82 + * but no real compatible string has been given. 83 + */ 84 + dev_info(&i2c->dev, "matching on node name, compatible is preferred\n"); 85 + partnum = id->driver_data; 86 + } else 87 + partnum = (int)of_id->data; 88 + 89 + return stmpe_probe(&i2c_ci, partnum); 65 90 } 66 91 67 92 static int stmpe_i2c_remove(struct i2c_client *i2c) ··· 116 89 #ifdef CONFIG_PM 117 90 .pm = &stmpe_dev_pm_ops, 118 91 #endif 92 + .of_match_table = stmpe_of_match, 119 93 }, 120 94 .probe = stmpe_i2c_probe, 121 95 .remove = stmpe_i2c_remove,
+28 -5
drivers/mfd/stmpe.c
··· 20 20 #include <linux/slab.h> 21 21 #include <linux/mfd/core.h> 22 22 #include <linux/delay.h> 23 + #include <linux/regulator/consumer.h> 23 24 #include "stmpe.h" 24 25 25 26 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks) ··· 606 605 607 606 if (blocks & STMPE_BLOCK_GPIO) 608 607 mask |= STMPE1601_SYS_CTRL_ENABLE_GPIO; 608 + else 609 + mask &= ~STMPE1601_SYS_CTRL_ENABLE_GPIO; 609 610 610 611 if (blocks & STMPE_BLOCK_KEYPAD) 611 612 mask |= STMPE1601_SYS_CTRL_ENABLE_KPC; 613 + else 614 + mask &= ~STMPE1601_SYS_CTRL_ENABLE_KPC; 615 + 616 + if (blocks & STMPE_BLOCK_PWM) 617 + mask |= STMPE1601_SYS_CTRL_ENABLE_SPWM; 618 + else 619 + mask &= ~STMPE1601_SYS_CTRL_ENABLE_SPWM; 612 620 613 621 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask, 614 622 enable ? mask : 0); ··· 996 986 int base = 0; 997 987 int num_irqs = stmpe->variant->num_irqs; 998 988 999 - if (!np) 1000 - base = stmpe->irq_base; 1001 - 1002 989 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, 1003 990 &stmpe_irq_ops, stmpe); 1004 991 if (!stmpe->domain) { ··· 1074 1067 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) 1075 1068 { 1076 1069 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, 1077 - NULL, stmpe->irq_base, stmpe->domain); 1070 + NULL, 0, stmpe->domain); 1078 1071 } 1079 1072 1080 1073 static int stmpe_devices_init(struct stmpe *stmpe) ··· 1178 1171 stmpe->dev = ci->dev; 1179 1172 stmpe->client = ci->client; 1180 1173 stmpe->pdata = pdata; 1181 - stmpe->irq_base = pdata->irq_base; 1182 1174 stmpe->ci = ci; 1183 1175 stmpe->partnum = partnum; 1184 1176 stmpe->variant = stmpe_variant_info[partnum]; 1185 1177 stmpe->regs = stmpe->variant->regs; 1186 1178 stmpe->num_gpios = stmpe->variant->num_gpios; 1179 + stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); 1180 + if (!IS_ERR(stmpe->vcc)) { 1181 + ret = regulator_enable(stmpe->vcc); 1182 + if (ret) 1183 + dev_warn(ci->dev, "failed to enable VCC supply\n"); 1184 + } 1185 + stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); 1186 + if (!IS_ERR(stmpe->vio)) { 1187 + ret = regulator_enable(stmpe->vio); 1188 + if (ret) 1189 + dev_warn(ci->dev, "failed to enable VIO supply\n"); 1190 + } 1187 1191 dev_set_drvdata(stmpe->dev, stmpe); 1188 1192 1189 1193 if (ci->init) ··· 1261 1243 1262 1244 int stmpe_remove(struct stmpe *stmpe) 1263 1245 { 1246 + if (!IS_ERR(stmpe->vio)) 1247 + regulator_disable(stmpe->vio); 1248 + if (!IS_ERR(stmpe->vcc)) 1249 + regulator_disable(stmpe->vcc); 1250 + 1264 1251 mfd_remove_devices(stmpe->dev); 1265 1252 1266 1253 return 0;
+1 -1
drivers/mfd/stmpe.h
··· 192 192 193 193 #define STMPE1601_SYS_CTRL_ENABLE_GPIO (1 << 3) 194 194 #define STMPE1601_SYS_CTRL_ENABLE_KPC (1 << 1) 195 - #define STMPE1601_SYSCON_ENABLE_SPWM (1 << 0) 195 + #define STMPE1601_SYS_CTRL_ENABLE_SPWM (1 << 0) 196 196 197 197 /* The 1601/2403 share the same masks */ 198 198 #define STMPE1601_AUTOSLEEP_TIMEOUT_MASK (0x7)
+25 -16
drivers/mfd/tps65090.c
··· 32 32 #define NUM_INT_REG 2 33 33 #define TOTAL_NUM_REG 0x18 34 34 35 - /* interrupt status registers */ 36 - #define TPS65090_INT_STS 0x0 37 - #define TPS65090_INT_STS2 0x1 38 - 39 - /* interrupt mask registers */ 40 - #define TPS65090_INT_MSK 0x2 41 - #define TPS65090_INT_MSK2 0x3 42 - 43 35 #define TPS65090_INT1_MASK_VAC_STATUS_CHANGE 1 44 36 #define TPS65090_INT1_MASK_VSYS_STATUS_CHANGE 2 45 37 #define TPS65090_INT1_MASK_BAT_STATUS_CHANGE 3 ··· 56 64 } 57 65 }; 58 66 59 - static const struct mfd_cell tps65090s[] = { 60 - { 67 + enum tps65090_cells { 68 + PMIC = 0, 69 + CHARGER = 1, 70 + }; 71 + 72 + static struct mfd_cell tps65090s[] = { 73 + [PMIC] = { 61 74 .name = "tps65090-pmic", 62 75 }, 63 - { 76 + [CHARGER] = { 64 77 .name = "tps65090-charger", 65 78 .num_resources = ARRAY_SIZE(charger_resources), 66 79 .resources = &charger_resources[0], ··· 136 139 .irqs = tps65090_irqs, 137 140 .num_irqs = ARRAY_SIZE(tps65090_irqs), 138 141 .num_regs = NUM_INT_REG, 139 - .status_base = TPS65090_INT_STS, 140 - .mask_base = TPS65090_INT_MSK, 142 + .status_base = TPS65090_REG_INTR_STS, 143 + .mask_base = TPS65090_REG_INTR_MASK, 141 144 .mask_invert = true, 142 145 }; 143 146 144 147 static bool is_volatile_reg(struct device *dev, unsigned int reg) 145 148 { 146 - if ((reg == TPS65090_INT_STS) || (reg == TPS65090_INT_STS2)) 147 - return true; 148 - else 149 + /* Nearly all registers have status bits mixed in, except a few */ 150 + switch (reg) { 151 + case TPS65090_REG_INTR_MASK: 152 + case TPS65090_REG_INTR_MASK2: 153 + case TPS65090_REG_CG_CTRL0: 154 + case TPS65090_REG_CG_CTRL1: 155 + case TPS65090_REG_CG_CTRL2: 156 + case TPS65090_REG_CG_CTRL3: 157 + case TPS65090_REG_CG_CTRL4: 158 + case TPS65090_REG_CG_CTRL5: 149 159 return false; 160 + } 161 + return true; 150 162 } 151 163 152 164 static const struct regmap_config tps65090_regmap_config = { ··· 217 211 "IRQ init failed with err: %d\n", ret); 218 212 return ret; 219 213 } 214 + } else { 215 + /* Don't tell children they have an IRQ that'll never fire */ 216 + tps65090s[CHARGER].num_resources = 0; 220 217 } 221 218 222 219 ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
+4
drivers/mfd/tps6586x.c
··· 495 495 case TPS658623: 496 496 name = "TPS658623"; 497 497 break; 498 + case TPS658640: 499 + case TPS658640v2: 500 + name = "TPS658640"; 501 + break; 498 502 case TPS658643: 499 503 name = "TPS658643"; 500 504 break;
+15
drivers/mfd/twl-core.c
··· 98 98 #define TWL4030_BASEADD_BACKUP 0x0014 99 99 #define TWL4030_BASEADD_INT 0x002E 100 100 #define TWL4030_BASEADD_PM_MASTER 0x0036 101 + 101 102 #define TWL4030_BASEADD_PM_RECEIVER 0x005B 103 + #define TWL4030_DCDC_GLOBAL_CFG 0x06 104 + #define SMARTREFLEX_ENABLE BIT(3) 105 + 102 106 #define TWL4030_BASEADD_RTC 0x001C 103 107 #define TWL4030_BASEADD_SECURED_REG 0x0000 104 108 ··· 1208 1204 * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. 1209 1205 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, 1210 1206 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. 1207 + * 1208 + * Also, always enable SmartReflex bit as that's needed for omaps to 1209 + * to do anything over I2C4 for voltage scaling even if SmartReflex 1210 + * is disabled. Without the SmartReflex bit omap sys_clkreq idle 1211 + * signal will never trigger for retention idle. 1211 1212 */ 1212 1213 if (twl_class_is_4030()) { 1213 1214 u8 temp; ··· 1221 1212 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ 1222 1213 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); 1223 1214 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); 1215 + 1216 + twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &temp, 1217 + TWL4030_DCDC_GLOBAL_CFG); 1218 + temp |= SMARTREFLEX_ENABLE; 1219 + twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, temp, 1220 + TWL4030_DCDC_GLOBAL_CFG); 1224 1221 } 1225 1222 1226 1223 if (node) {
+7
drivers/mmc/host/Kconfig
··· 694 694 help 695 695 Say Y here to include driver code to support SD/MMC card interface 696 696 of Realtek PCI-E card reader 697 + 698 + config MMC_REALTEK_USB 699 + tristate "Realtek USB SD/MMC Card Interface Driver" 700 + depends on MFD_RTSX_USB 701 + help 702 + Say Y here to include driver code to support SD/MMC card interface 703 + of Realtek RTS5129/39 series card reader
+1
drivers/mmc/host/Makefile
··· 52 52 obj-$(CONFIG_MMC_WMT) += wmt-sdmmc.o 53 53 54 54 obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o 55 + obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o 55 56 56 57 obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o 57 58 obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
+1455
drivers/mmc/host/rtsx_usb_sdmmc.c
··· 1 + /* Realtek USB SD/MMC Card Interface driver 2 + * 3 + * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms of the GNU General Public License version 2 7 + * as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, but 10 + * WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 + * General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License along 15 + * with this program; if not, see <http://www.gnu.org/licenses/>. 16 + * 17 + * Author: 18 + * Roger Tseng <rogerable@realtek.com> 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/slab.h> 23 + #include <linux/delay.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/usb.h> 26 + #include <linux/mmc/host.h> 27 + #include <linux/mmc/mmc.h> 28 + #include <linux/mmc/sd.h> 29 + #include <linux/mmc/sdio.h> 30 + #include <linux/mmc/card.h> 31 + #include <linux/scatterlist.h> 32 + #include <linux/pm_runtime.h> 33 + 34 + #include <linux/mfd/rtsx_usb.h> 35 + #include <asm/unaligned.h> 36 + 37 + #if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE) 38 + #include <linux/leds.h> 39 + #include <linux/workqueue.h> 40 + #define RTSX_USB_USE_LEDS_CLASS 41 + #endif 42 + 43 + struct rtsx_usb_sdmmc { 44 + struct platform_device *pdev; 45 + struct rtsx_ucr *ucr; 46 + struct mmc_host *mmc; 47 + struct mmc_request *mrq; 48 + 49 + struct mutex host_mutex; 50 + 51 + u8 ssc_depth; 52 + unsigned int clock; 53 + bool vpclk; 54 + bool double_clk; 55 + bool host_removal; 56 + bool card_exist; 57 + bool initial_mode; 58 + bool ddr_mode; 59 + 60 + unsigned char power_mode; 61 + 62 + #if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE) 63 + struct led_classdev led; 64 + char led_name[32]; 65 + struct work_struct led_work; 66 + #endif 67 + }; 68 + 69 + static inline struct device *sdmmc_dev(struct rtsx_usb_sdmmc *host) 70 + { 71 + return &(host->pdev->dev); 72 + } 73 + 74 + static inline void sd_clear_error(struct rtsx_usb_sdmmc *host) 75 + { 76 + struct rtsx_ucr *ucr = host->ucr; 77 + rtsx_usb_ep0_write_register(ucr, CARD_STOP, 78 + SD_STOP | SD_CLR_ERR, 79 + SD_STOP | SD_CLR_ERR); 80 + 81 + rtsx_usb_clear_dma_err(ucr); 82 + rtsx_usb_clear_fsm_err(ucr); 83 + } 84 + 85 + #ifdef DEBUG 86 + static void sd_print_debug_regs(struct rtsx_usb_sdmmc *host) 87 + { 88 + struct rtsx_ucr *ucr = host->ucr; 89 + u8 val = 0; 90 + 91 + rtsx_usb_ep0_read_register(ucr, SD_STAT1, &val); 92 + dev_dbg(sdmmc_dev(host), "SD_STAT1: 0x%x\n", val); 93 + rtsx_usb_ep0_read_register(ucr, SD_STAT2, &val); 94 + dev_dbg(sdmmc_dev(host), "SD_STAT2: 0x%x\n", val); 95 + rtsx_usb_ep0_read_register(ucr, SD_BUS_STAT, &val); 96 + dev_dbg(sdmmc_dev(host), "SD_BUS_STAT: 0x%x\n", val); 97 + } 98 + #else 99 + #define sd_print_debug_regs(host) 100 + #endif /* DEBUG */ 101 + 102 + static int sd_read_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd, 103 + u16 byte_cnt, u8 *buf, int buf_len, int timeout) 104 + { 105 + struct rtsx_ucr *ucr = host->ucr; 106 + int err; 107 + u8 trans_mode; 108 + 109 + if (!buf) 110 + buf_len = 0; 111 + 112 + rtsx_usb_init_cmd(ucr); 113 + if (cmd != NULL) { 114 + dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__ 115 + , cmd->opcode); 116 + if (cmd->opcode == MMC_SEND_TUNING_BLOCK) 117 + trans_mode = SD_TM_AUTO_TUNING; 118 + else 119 + trans_mode = SD_TM_NORMAL_READ; 120 + 121 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 122 + SD_CMD0, 0xFF, (u8)(cmd->opcode) | 0x40); 123 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 124 + SD_CMD1, 0xFF, (u8)(cmd->arg >> 24)); 125 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 126 + SD_CMD2, 0xFF, (u8)(cmd->arg >> 16)); 127 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 128 + SD_CMD3, 0xFF, (u8)(cmd->arg >> 8)); 129 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 130 + SD_CMD4, 0xFF, (u8)cmd->arg); 131 + } else { 132 + trans_mode = SD_TM_AUTO_READ_3; 133 + } 134 + 135 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_L, 0xFF, (u8)byte_cnt); 136 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_H, 137 + 0xFF, (u8)(byte_cnt >> 8)); 138 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_L, 0xFF, 1); 139 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_H, 0xFF, 0); 140 + 141 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG2, 0xFF, 142 + SD_CALCULATE_CRC7 | SD_CHECK_CRC16 | 143 + SD_NO_WAIT_BUSY_END | SD_CHECK_CRC7 | SD_RSP_LEN_6); 144 + if (trans_mode != SD_TM_AUTO_TUNING) 145 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 146 + CARD_DATA_SOURCE, 0x01, PINGPONG_BUFFER); 147 + 148 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_TRANSFER, 149 + 0xFF, trans_mode | SD_TRANSFER_START); 150 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, SD_TRANSFER, 151 + SD_TRANSFER_END, SD_TRANSFER_END); 152 + 153 + if (cmd != NULL) { 154 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD1, 0, 0); 155 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD2, 0, 0); 156 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD3, 0, 0); 157 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD4, 0, 0); 158 + } 159 + 160 + err = rtsx_usb_send_cmd(ucr, MODE_CR, timeout); 161 + if (err) { 162 + dev_dbg(sdmmc_dev(host), 163 + "rtsx_usb_send_cmd failed (err = %d)\n", err); 164 + return err; 165 + } 166 + 167 + err = rtsx_usb_get_rsp(ucr, !cmd ? 1 : 5, timeout); 168 + if (err || (ucr->rsp_buf[0] & SD_TRANSFER_ERR)) { 169 + sd_print_debug_regs(host); 170 + 171 + if (!err) { 172 + dev_dbg(sdmmc_dev(host), 173 + "Transfer failed (SD_TRANSFER = %02x)\n", 174 + ucr->rsp_buf[0]); 175 + err = -EIO; 176 + } else { 177 + dev_dbg(sdmmc_dev(host), 178 + "rtsx_usb_get_rsp failed (err = %d)\n", err); 179 + } 180 + 181 + return err; 182 + } 183 + 184 + if (cmd != NULL) { 185 + cmd->resp[0] = get_unaligned_be32(ucr->rsp_buf + 1); 186 + dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", 187 + cmd->resp[0]); 188 + } 189 + 190 + if (buf && buf_len) { 191 + /* 2-byte aligned part */ 192 + err = rtsx_usb_read_ppbuf(ucr, buf, byte_cnt - (byte_cnt % 2)); 193 + if (err) { 194 + dev_dbg(sdmmc_dev(host), 195 + "rtsx_usb_read_ppbuf failed (err = %d)\n", err); 196 + return err; 197 + } 198 + 199 + /* unaligned byte */ 200 + if (byte_cnt % 2) 201 + return rtsx_usb_read_register(ucr, 202 + PPBUF_BASE2 + byte_cnt, 203 + buf + byte_cnt - 1); 204 + } 205 + 206 + return 0; 207 + } 208 + 209 + static int sd_write_data(struct rtsx_usb_sdmmc *host, struct mmc_command *cmd, 210 + u16 byte_cnt, u8 *buf, int buf_len, int timeout) 211 + { 212 + struct rtsx_ucr *ucr = host->ucr; 213 + int err; 214 + u8 trans_mode; 215 + 216 + if (!buf) 217 + buf_len = 0; 218 + 219 + if (buf && buf_len) { 220 + err = rtsx_usb_write_ppbuf(ucr, buf, buf_len); 221 + if (err) { 222 + dev_dbg(sdmmc_dev(host), 223 + "rtsx_usb_write_ppbuf failed (err = %d)\n", 224 + err); 225 + return err; 226 + } 227 + } 228 + 229 + trans_mode = (cmd != NULL) ? SD_TM_AUTO_WRITE_2 : SD_TM_AUTO_WRITE_3; 230 + rtsx_usb_init_cmd(ucr); 231 + 232 + if (cmd != NULL) { 233 + dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD%d\n", __func__, 234 + cmd->opcode); 235 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 236 + SD_CMD0, 0xFF, (u8)(cmd->opcode) | 0x40); 237 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 238 + SD_CMD1, 0xFF, (u8)(cmd->arg >> 24)); 239 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 240 + SD_CMD2, 0xFF, (u8)(cmd->arg >> 16)); 241 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 242 + SD_CMD3, 0xFF, (u8)(cmd->arg >> 8)); 243 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 244 + SD_CMD4, 0xFF, (u8)cmd->arg); 245 + } 246 + 247 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_L, 0xFF, (u8)byte_cnt); 248 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_H, 249 + 0xFF, (u8)(byte_cnt >> 8)); 250 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_L, 0xFF, 1); 251 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_H, 0xFF, 0); 252 + 253 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG2, 0xFF, 254 + SD_CALCULATE_CRC7 | SD_CHECK_CRC16 | 255 + SD_NO_WAIT_BUSY_END | SD_CHECK_CRC7 | SD_RSP_LEN_6); 256 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 257 + CARD_DATA_SOURCE, 0x01, PINGPONG_BUFFER); 258 + 259 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_TRANSFER, 0xFF, 260 + trans_mode | SD_TRANSFER_START); 261 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, SD_TRANSFER, 262 + SD_TRANSFER_END, SD_TRANSFER_END); 263 + 264 + if (cmd != NULL) { 265 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD1, 0, 0); 266 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD2, 0, 0); 267 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD3, 0, 0); 268 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_CMD4, 0, 0); 269 + } 270 + 271 + err = rtsx_usb_send_cmd(ucr, MODE_CR, timeout); 272 + if (err) { 273 + dev_dbg(sdmmc_dev(host), 274 + "rtsx_usb_send_cmd failed (err = %d)\n", err); 275 + return err; 276 + } 277 + 278 + err = rtsx_usb_get_rsp(ucr, !cmd ? 1 : 5, timeout); 279 + if (err) { 280 + sd_print_debug_regs(host); 281 + dev_dbg(sdmmc_dev(host), 282 + "rtsx_usb_get_rsp failed (err = %d)\n", err); 283 + return err; 284 + } 285 + 286 + if (cmd != NULL) { 287 + cmd->resp[0] = get_unaligned_be32(ucr->rsp_buf + 1); 288 + dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", 289 + cmd->resp[0]); 290 + } 291 + 292 + return 0; 293 + } 294 + 295 + static void sd_send_cmd_get_rsp(struct rtsx_usb_sdmmc *host, 296 + struct mmc_command *cmd) 297 + { 298 + struct rtsx_ucr *ucr = host->ucr; 299 + u8 cmd_idx = (u8)cmd->opcode; 300 + u32 arg = cmd->arg; 301 + int err = 0; 302 + int timeout = 100; 303 + int i; 304 + u8 *ptr; 305 + int stat_idx = 0; 306 + int len = 2; 307 + u8 rsp_type; 308 + 309 + dev_dbg(sdmmc_dev(host), "%s: SD/MMC CMD %d, arg = 0x%08x\n", 310 + __func__, cmd_idx, arg); 311 + 312 + /* Response type: 313 + * R0 314 + * R1, R5, R6, R7 315 + * R1b 316 + * R2 317 + * R3, R4 318 + */ 319 + switch (mmc_resp_type(cmd)) { 320 + case MMC_RSP_NONE: 321 + rsp_type = SD_RSP_TYPE_R0; 322 + break; 323 + case MMC_RSP_R1: 324 + rsp_type = SD_RSP_TYPE_R1; 325 + break; 326 + case MMC_RSP_R1 & ~MMC_RSP_CRC: 327 + rsp_type = SD_RSP_TYPE_R1 | SD_NO_CHECK_CRC7; 328 + break; 329 + case MMC_RSP_R1B: 330 + rsp_type = SD_RSP_TYPE_R1b; 331 + break; 332 + case MMC_RSP_R2: 333 + rsp_type = SD_RSP_TYPE_R2; 334 + break; 335 + case MMC_RSP_R3: 336 + rsp_type = SD_RSP_TYPE_R3; 337 + break; 338 + default: 339 + dev_dbg(sdmmc_dev(host), "cmd->flag is not valid\n"); 340 + err = -EINVAL; 341 + goto out; 342 + } 343 + 344 + if (rsp_type == SD_RSP_TYPE_R1b) 345 + timeout = 3000; 346 + 347 + if (cmd->opcode == SD_SWITCH_VOLTAGE) { 348 + err = rtsx_usb_write_register(ucr, SD_BUS_STAT, 349 + SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 350 + SD_CLK_TOGGLE_EN); 351 + if (err) 352 + goto out; 353 + } 354 + 355 + rtsx_usb_init_cmd(ucr); 356 + 357 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CMD0, 0xFF, 0x40 | cmd_idx); 358 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CMD1, 0xFF, (u8)(arg >> 24)); 359 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CMD2, 0xFF, (u8)(arg >> 16)); 360 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CMD3, 0xFF, (u8)(arg >> 8)); 361 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CMD4, 0xFF, (u8)arg); 362 + 363 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG2, 0xFF, rsp_type); 364 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_DATA_SOURCE, 365 + 0x01, PINGPONG_BUFFER); 366 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_TRANSFER, 367 + 0xFF, SD_TM_CMD_RSP | SD_TRANSFER_START); 368 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, SD_TRANSFER, 369 + SD_TRANSFER_END | SD_STAT_IDLE, 370 + SD_TRANSFER_END | SD_STAT_IDLE); 371 + 372 + if (rsp_type == SD_RSP_TYPE_R2) { 373 + /* Read data from ping-pong buffer */ 374 + for (i = PPBUF_BASE2; i < PPBUF_BASE2 + 16; i++) 375 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, (u16)i, 0, 0); 376 + stat_idx = 16; 377 + } else if (rsp_type != SD_RSP_TYPE_R0) { 378 + /* Read data from SD_CMDx registers */ 379 + for (i = SD_CMD0; i <= SD_CMD4; i++) 380 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, (u16)i, 0, 0); 381 + stat_idx = 5; 382 + } 383 + len += stat_idx; 384 + 385 + rtsx_usb_add_cmd(ucr, READ_REG_CMD, SD_STAT1, 0, 0); 386 + 387 + err = rtsx_usb_send_cmd(ucr, MODE_CR, 100); 388 + if (err) { 389 + dev_dbg(sdmmc_dev(host), 390 + "rtsx_usb_send_cmd error (err = %d)\n", err); 391 + goto out; 392 + } 393 + 394 + err = rtsx_usb_get_rsp(ucr, len, timeout); 395 + if (err || (ucr->rsp_buf[0] & SD_TRANSFER_ERR)) { 396 + sd_print_debug_regs(host); 397 + sd_clear_error(host); 398 + 399 + if (!err) { 400 + dev_dbg(sdmmc_dev(host), 401 + "Transfer failed (SD_TRANSFER = %02x)\n", 402 + ucr->rsp_buf[0]); 403 + err = -EIO; 404 + } else { 405 + dev_dbg(sdmmc_dev(host), 406 + "rtsx_usb_get_rsp failed (err = %d)\n", err); 407 + } 408 + 409 + goto out; 410 + } 411 + 412 + if (rsp_type == SD_RSP_TYPE_R0) { 413 + err = 0; 414 + goto out; 415 + } 416 + 417 + /* Skip result of CHECK_REG_CMD */ 418 + ptr = ucr->rsp_buf + 1; 419 + 420 + /* Check (Start,Transmission) bit of Response */ 421 + if ((ptr[0] & 0xC0) != 0) { 422 + err = -EILSEQ; 423 + dev_dbg(sdmmc_dev(host), "Invalid response bit\n"); 424 + goto out; 425 + } 426 + 427 + /* Check CRC7 */ 428 + if (!(rsp_type & SD_NO_CHECK_CRC7)) { 429 + if (ptr[stat_idx] & SD_CRC7_ERR) { 430 + err = -EILSEQ; 431 + dev_dbg(sdmmc_dev(host), "CRC7 error\n"); 432 + goto out; 433 + } 434 + } 435 + 436 + if (rsp_type == SD_RSP_TYPE_R2) { 437 + for (i = 0; i < 4; i++) { 438 + cmd->resp[i] = get_unaligned_be32(ptr + 1 + i * 4); 439 + dev_dbg(sdmmc_dev(host), "cmd->resp[%d] = 0x%08x\n", 440 + i, cmd->resp[i]); 441 + } 442 + } else { 443 + cmd->resp[0] = get_unaligned_be32(ptr + 1); 444 + dev_dbg(sdmmc_dev(host), "cmd->resp[0] = 0x%08x\n", 445 + cmd->resp[0]); 446 + } 447 + 448 + out: 449 + cmd->error = err; 450 + } 451 + 452 + static int sd_rw_multi(struct rtsx_usb_sdmmc *host, struct mmc_request *mrq) 453 + { 454 + struct rtsx_ucr *ucr = host->ucr; 455 + struct mmc_data *data = mrq->data; 456 + int read = (data->flags & MMC_DATA_READ) ? 1 : 0; 457 + u8 cfg2, trans_mode; 458 + int err; 459 + u8 flag; 460 + size_t data_len = data->blksz * data->blocks; 461 + unsigned int pipe; 462 + 463 + if (read) { 464 + dev_dbg(sdmmc_dev(host), "%s: read %zu bytes\n", 465 + __func__, data_len); 466 + cfg2 = SD_CALCULATE_CRC7 | SD_CHECK_CRC16 | 467 + SD_NO_WAIT_BUSY_END | SD_CHECK_CRC7 | SD_RSP_LEN_0; 468 + trans_mode = SD_TM_AUTO_READ_3; 469 + } else { 470 + dev_dbg(sdmmc_dev(host), "%s: write %zu bytes\n", 471 + __func__, data_len); 472 + cfg2 = SD_NO_CALCULATE_CRC7 | SD_CHECK_CRC16 | 473 + SD_NO_WAIT_BUSY_END | SD_NO_CHECK_CRC7 | SD_RSP_LEN_0; 474 + trans_mode = SD_TM_AUTO_WRITE_3; 475 + } 476 + 477 + rtsx_usb_init_cmd(ucr); 478 + 479 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_L, 0xFF, 0x00); 480 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BYTE_CNT_H, 0xFF, 0x02); 481 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_L, 482 + 0xFF, (u8)data->blocks); 483 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BLOCK_CNT_H, 484 + 0xFF, (u8)(data->blocks >> 8)); 485 + 486 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_DATA_SOURCE, 487 + 0x01, RING_BUFFER); 488 + 489 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC3, 490 + 0xFF, (u8)(data_len >> 24)); 491 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC2, 492 + 0xFF, (u8)(data_len >> 16)); 493 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC1, 494 + 0xFF, (u8)(data_len >> 8)); 495 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_TC0, 496 + 0xFF, (u8)data_len); 497 + if (read) { 498 + flag = MODE_CDIR; 499 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_CTL, 500 + 0x03 | DMA_PACK_SIZE_MASK, 501 + DMA_DIR_FROM_CARD | DMA_EN | DMA_512); 502 + } else { 503 + flag = MODE_CDOR; 504 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, MC_DMA_CTL, 505 + 0x03 | DMA_PACK_SIZE_MASK, 506 + DMA_DIR_TO_CARD | DMA_EN | DMA_512); 507 + } 508 + 509 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG2, 0xFF, cfg2); 510 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_TRANSFER, 0xFF, 511 + trans_mode | SD_TRANSFER_START); 512 + rtsx_usb_add_cmd(ucr, CHECK_REG_CMD, SD_TRANSFER, 513 + SD_TRANSFER_END, SD_TRANSFER_END); 514 + 515 + err = rtsx_usb_send_cmd(ucr, flag, 100); 516 + if (err) 517 + return err; 518 + 519 + if (read) 520 + pipe = usb_rcvbulkpipe(ucr->pusb_dev, EP_BULK_IN); 521 + else 522 + pipe = usb_sndbulkpipe(ucr->pusb_dev, EP_BULK_OUT); 523 + 524 + err = rtsx_usb_transfer_data(ucr, pipe, data->sg, data_len, 525 + data->sg_len, NULL, 10000); 526 + if (err) { 527 + dev_dbg(sdmmc_dev(host), "rtsx_usb_transfer_data error %d\n" 528 + , err); 529 + sd_clear_error(host); 530 + return err; 531 + } 532 + 533 + return rtsx_usb_get_rsp(ucr, 1, 2000); 534 + } 535 + 536 + static inline void sd_enable_initial_mode(struct rtsx_usb_sdmmc *host) 537 + { 538 + rtsx_usb_write_register(host->ucr, SD_CFG1, 539 + SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128); 540 + } 541 + 542 + static inline void sd_disable_initial_mode(struct rtsx_usb_sdmmc *host) 543 + { 544 + rtsx_usb_write_register(host->ucr, SD_CFG1, 545 + SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); 546 + } 547 + 548 + static void sd_normal_rw(struct rtsx_usb_sdmmc *host, 549 + struct mmc_request *mrq) 550 + { 551 + struct mmc_command *cmd = mrq->cmd; 552 + struct mmc_data *data = mrq->data; 553 + u8 *buf; 554 + 555 + buf = kzalloc(data->blksz, GFP_NOIO); 556 + if (!buf) { 557 + cmd->error = -ENOMEM; 558 + return; 559 + } 560 + 561 + if (data->flags & MMC_DATA_READ) { 562 + if (host->initial_mode) 563 + sd_disable_initial_mode(host); 564 + 565 + cmd->error = sd_read_data(host, cmd, (u16)data->blksz, buf, 566 + data->blksz, 200); 567 + 568 + if (host->initial_mode) 569 + sd_enable_initial_mode(host); 570 + 571 + sg_copy_from_buffer(data->sg, data->sg_len, buf, data->blksz); 572 + } else { 573 + sg_copy_to_buffer(data->sg, data->sg_len, buf, data->blksz); 574 + 575 + cmd->error = sd_write_data(host, cmd, (u16)data->blksz, buf, 576 + data->blksz, 200); 577 + } 578 + 579 + kfree(buf); 580 + } 581 + 582 + static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx) 583 + { 584 + struct rtsx_ucr *ucr = host->ucr; 585 + int err; 586 + 587 + dev_dbg(sdmmc_dev(host), "%s: %s sample_point = %d\n", 588 + __func__, tx ? "TX" : "RX", sample_point); 589 + 590 + rtsx_usb_init_cmd(ucr); 591 + 592 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CLK_DIV, CLK_CHANGE, CLK_CHANGE); 593 + 594 + if (tx) 595 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_VPCLK0_CTL, 596 + 0x0F, sample_point); 597 + else 598 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_VPCLK1_CTL, 599 + 0x0F, sample_point); 600 + 601 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_VPCLK0_CTL, PHASE_NOT_RESET, 0); 602 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_VPCLK0_CTL, 603 + PHASE_NOT_RESET, PHASE_NOT_RESET); 604 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CLK_DIV, CLK_CHANGE, 0); 605 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG1, SD_ASYNC_FIFO_RST, 0); 606 + 607 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 608 + if (err) 609 + return err; 610 + 611 + return 0; 612 + } 613 + 614 + static inline u32 get_phase_point(u32 phase_map, unsigned int idx) 615 + { 616 + idx &= MAX_PHASE; 617 + return phase_map & (1 << idx); 618 + } 619 + 620 + static int get_phase_len(u32 phase_map, unsigned int idx) 621 + { 622 + int i; 623 + 624 + for (i = 0; i < MAX_PHASE + 1; i++) { 625 + if (get_phase_point(phase_map, idx + i) == 0) 626 + return i; 627 + } 628 + return MAX_PHASE + 1; 629 + } 630 + 631 + static u8 sd_search_final_phase(struct rtsx_usb_sdmmc *host, u32 phase_map) 632 + { 633 + int start = 0, len = 0; 634 + int start_final = 0, len_final = 0; 635 + u8 final_phase = 0xFF; 636 + 637 + if (phase_map == 0) { 638 + dev_dbg(sdmmc_dev(host), "Phase: [map:%x]\n", phase_map); 639 + return final_phase; 640 + } 641 + 642 + while (start < MAX_PHASE + 1) { 643 + len = get_phase_len(phase_map, start); 644 + if (len_final < len) { 645 + start_final = start; 646 + len_final = len; 647 + } 648 + start += len ? len : 1; 649 + } 650 + 651 + final_phase = (start_final + len_final / 2) & MAX_PHASE; 652 + dev_dbg(sdmmc_dev(host), "Phase: [map:%x] [maxlen:%d] [final:%d]\n", 653 + phase_map, len_final, final_phase); 654 + 655 + return final_phase; 656 + } 657 + 658 + static void sd_wait_data_idle(struct rtsx_usb_sdmmc *host) 659 + { 660 + int err, i; 661 + u8 val = 0; 662 + 663 + for (i = 0; i < 100; i++) { 664 + err = rtsx_usb_ep0_read_register(host->ucr, 665 + SD_DATA_STATE, &val); 666 + if (val & SD_DATA_IDLE) 667 + return; 668 + 669 + usleep_range(100, 1000); 670 + } 671 + } 672 + 673 + static int sd_tuning_rx_cmd(struct rtsx_usb_sdmmc *host, 674 + u8 opcode, u8 sample_point) 675 + { 676 + int err; 677 + struct mmc_command cmd = {0}; 678 + 679 + err = sd_change_phase(host, sample_point, 0); 680 + if (err) 681 + return err; 682 + 683 + cmd.opcode = MMC_SEND_TUNING_BLOCK; 684 + err = sd_read_data(host, &cmd, 0x40, NULL, 0, 100); 685 + if (err) { 686 + /* Wait till SD DATA IDLE */ 687 + sd_wait_data_idle(host); 688 + sd_clear_error(host); 689 + return err; 690 + } 691 + 692 + return 0; 693 + } 694 + 695 + static void sd_tuning_phase(struct rtsx_usb_sdmmc *host, 696 + u8 opcode, u16 *phase_map) 697 + { 698 + int err, i; 699 + u16 raw_phase_map = 0; 700 + 701 + for (i = MAX_PHASE; i >= 0; i--) { 702 + err = sd_tuning_rx_cmd(host, opcode, (u8)i); 703 + if (!err) 704 + raw_phase_map |= 1 << i; 705 + } 706 + 707 + if (phase_map) 708 + *phase_map = raw_phase_map; 709 + } 710 + 711 + static int sd_tuning_rx(struct rtsx_usb_sdmmc *host, u8 opcode) 712 + { 713 + int err, i; 714 + u16 raw_phase_map[RX_TUNING_CNT] = {0}, phase_map; 715 + u8 final_phase; 716 + 717 + /* setting fixed default TX phase */ 718 + err = sd_change_phase(host, 0x01, 1); 719 + if (err) { 720 + dev_dbg(sdmmc_dev(host), "TX phase setting failed\n"); 721 + return err; 722 + } 723 + 724 + /* tuning RX phase */ 725 + for (i = 0; i < RX_TUNING_CNT; i++) { 726 + sd_tuning_phase(host, opcode, &(raw_phase_map[i])); 727 + 728 + if (raw_phase_map[i] == 0) 729 + break; 730 + } 731 + 732 + phase_map = 0xFFFF; 733 + for (i = 0; i < RX_TUNING_CNT; i++) { 734 + dev_dbg(sdmmc_dev(host), "RX raw_phase_map[%d] = 0x%04x\n", 735 + i, raw_phase_map[i]); 736 + phase_map &= raw_phase_map[i]; 737 + } 738 + dev_dbg(sdmmc_dev(host), "RX phase_map = 0x%04x\n", phase_map); 739 + 740 + if (phase_map) { 741 + final_phase = sd_search_final_phase(host, phase_map); 742 + if (final_phase == 0xFF) 743 + return -EINVAL; 744 + 745 + err = sd_change_phase(host, final_phase, 0); 746 + if (err) 747 + return err; 748 + } else { 749 + return -EINVAL; 750 + } 751 + 752 + return 0; 753 + } 754 + 755 + static int sdmmc_get_ro(struct mmc_host *mmc) 756 + { 757 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 758 + struct rtsx_ucr *ucr = host->ucr; 759 + int err; 760 + u16 val; 761 + 762 + if (host->host_removal) 763 + return -ENOMEDIUM; 764 + 765 + mutex_lock(&ucr->dev_mutex); 766 + 767 + /* Check SD card detect */ 768 + err = rtsx_usb_get_card_status(ucr, &val); 769 + 770 + mutex_unlock(&ucr->dev_mutex); 771 + 772 + 773 + /* Treat failed detection as non-ro */ 774 + if (err) 775 + return 0; 776 + 777 + if (val & SD_WP) 778 + return 1; 779 + 780 + return 0; 781 + } 782 + 783 + static int sdmmc_get_cd(struct mmc_host *mmc) 784 + { 785 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 786 + struct rtsx_ucr *ucr = host->ucr; 787 + int err; 788 + u16 val; 789 + 790 + if (host->host_removal) 791 + return -ENOMEDIUM; 792 + 793 + mutex_lock(&ucr->dev_mutex); 794 + 795 + /* Check SD card detect */ 796 + err = rtsx_usb_get_card_status(ucr, &val); 797 + 798 + mutex_unlock(&ucr->dev_mutex); 799 + 800 + /* Treat failed detection as non-exist */ 801 + if (err) 802 + goto no_card; 803 + 804 + if (val & SD_CD) { 805 + host->card_exist = true; 806 + return 1; 807 + } 808 + 809 + no_card: 810 + host->card_exist = false; 811 + return 0; 812 + } 813 + 814 + static void sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq) 815 + { 816 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 817 + struct rtsx_ucr *ucr = host->ucr; 818 + struct mmc_command *cmd = mrq->cmd; 819 + struct mmc_data *data = mrq->data; 820 + unsigned int data_size = 0; 821 + 822 + dev_dbg(sdmmc_dev(host), "%s\n", __func__); 823 + 824 + if (host->host_removal) { 825 + cmd->error = -ENOMEDIUM; 826 + goto finish; 827 + } 828 + 829 + if ((!host->card_exist)) { 830 + cmd->error = -ENOMEDIUM; 831 + goto finish_detect_card; 832 + } 833 + 834 + /* 835 + * Reject SDIO CMDs to speed up card identification 836 + * since unsupported 837 + */ 838 + if (cmd->opcode == SD_IO_SEND_OP_COND || 839 + cmd->opcode == SD_IO_RW_DIRECT || 840 + cmd->opcode == SD_IO_RW_EXTENDED) { 841 + cmd->error = -EINVAL; 842 + goto finish; 843 + } 844 + 845 + mutex_lock(&ucr->dev_mutex); 846 + 847 + mutex_lock(&host->host_mutex); 848 + host->mrq = mrq; 849 + mutex_unlock(&host->host_mutex); 850 + 851 + if (mrq->data) 852 + data_size = data->blocks * data->blksz; 853 + 854 + if (!data_size) { 855 + sd_send_cmd_get_rsp(host, cmd); 856 + } else if ((!(data_size % 512) && cmd->opcode != MMC_SEND_EXT_CSD) || 857 + mmc_op_multi(cmd->opcode)) { 858 + sd_send_cmd_get_rsp(host, cmd); 859 + 860 + if (!cmd->error) { 861 + sd_rw_multi(host, mrq); 862 + 863 + if (mmc_op_multi(cmd->opcode) && mrq->stop) { 864 + sd_send_cmd_get_rsp(host, mrq->stop); 865 + rtsx_usb_write_register(ucr, MC_FIFO_CTL, 866 + FIFO_FLUSH, FIFO_FLUSH); 867 + } 868 + } 869 + } else { 870 + sd_normal_rw(host, mrq); 871 + } 872 + 873 + if (mrq->data) { 874 + if (cmd->error || data->error) 875 + data->bytes_xfered = 0; 876 + else 877 + data->bytes_xfered = data->blocks * data->blksz; 878 + } 879 + 880 + mutex_unlock(&ucr->dev_mutex); 881 + 882 + finish_detect_card: 883 + if (cmd->error) { 884 + /* 885 + * detect card when fail to update card existence state and 886 + * speed up card removal when retry 887 + */ 888 + sdmmc_get_cd(mmc); 889 + dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error); 890 + } 891 + 892 + finish: 893 + mutex_lock(&host->host_mutex); 894 + host->mrq = NULL; 895 + mutex_unlock(&host->host_mutex); 896 + 897 + mmc_request_done(mmc, mrq); 898 + } 899 + 900 + static int sd_set_bus_width(struct rtsx_usb_sdmmc *host, 901 + unsigned char bus_width) 902 + { 903 + int err = 0; 904 + u8 width[] = { 905 + [MMC_BUS_WIDTH_1] = SD_BUS_WIDTH_1BIT, 906 + [MMC_BUS_WIDTH_4] = SD_BUS_WIDTH_4BIT, 907 + [MMC_BUS_WIDTH_8] = SD_BUS_WIDTH_8BIT, 908 + }; 909 + 910 + if (bus_width <= MMC_BUS_WIDTH_8) 911 + err = rtsx_usb_write_register(host->ucr, SD_CFG1, 912 + 0x03, width[bus_width]); 913 + 914 + return err; 915 + } 916 + 917 + static int sd_pull_ctl_disable_lqfp48(struct rtsx_ucr *ucr) 918 + { 919 + rtsx_usb_init_cmd(ucr); 920 + 921 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x55); 922 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 923 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 924 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 925 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); 926 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0xA5); 927 + 928 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 929 + } 930 + 931 + static int sd_pull_ctl_disable_qfn24(struct rtsx_ucr *ucr) 932 + { 933 + rtsx_usb_init_cmd(ucr); 934 + 935 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0x65); 936 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x55); 937 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0x95); 938 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 939 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x56); 940 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0x59); 941 + 942 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 943 + } 944 + 945 + static int sd_pull_ctl_enable_lqfp48(struct rtsx_ucr *ucr) 946 + { 947 + rtsx_usb_init_cmd(ucr); 948 + 949 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0xAA); 950 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0xAA); 951 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0xA9); 952 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x55); 953 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x55); 954 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0xA5); 955 + 956 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 957 + } 958 + 959 + static int sd_pull_ctl_enable_qfn24(struct rtsx_ucr *ucr) 960 + { 961 + rtsx_usb_init_cmd(ucr); 962 + 963 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL1, 0xFF, 0xA5); 964 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL2, 0xFF, 0x9A); 965 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL3, 0xFF, 0xA5); 966 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL4, 0xFF, 0x9A); 967 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL5, 0xFF, 0x65); 968 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PULL_CTL6, 0xFF, 0x5A); 969 + 970 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 971 + } 972 + 973 + static int sd_power_on(struct rtsx_usb_sdmmc *host) 974 + { 975 + struct rtsx_ucr *ucr = host->ucr; 976 + int err; 977 + 978 + dev_dbg(sdmmc_dev(host), "%s\n", __func__); 979 + rtsx_usb_init_cmd(ucr); 980 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_SELECT, 0x07, SD_MOD_SEL); 981 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_SHARE_MODE, 982 + CARD_SHARE_MASK, CARD_SHARE_SD); 983 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_EN, 984 + SD_CLK_EN, SD_CLK_EN); 985 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 986 + if (err) 987 + return err; 988 + 989 + if (CHECK_PKG(ucr, LQFP48)) 990 + err = sd_pull_ctl_enable_lqfp48(ucr); 991 + else 992 + err = sd_pull_ctl_enable_qfn24(ucr); 993 + if (err) 994 + return err; 995 + 996 + err = rtsx_usb_write_register(ucr, CARD_PWR_CTL, 997 + POWER_MASK, PARTIAL_POWER_ON); 998 + if (err) 999 + return err; 1000 + 1001 + usleep_range(800, 1000); 1002 + 1003 + rtsx_usb_init_cmd(ucr); 1004 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL, 1005 + POWER_MASK|LDO3318_PWR_MASK, POWER_ON|LDO_ON); 1006 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_OE, 1007 + SD_OUTPUT_EN, SD_OUTPUT_EN); 1008 + 1009 + return rtsx_usb_send_cmd(ucr, MODE_C, 100); 1010 + } 1011 + 1012 + static int sd_power_off(struct rtsx_usb_sdmmc *host) 1013 + { 1014 + struct rtsx_ucr *ucr = host->ucr; 1015 + int err; 1016 + 1017 + dev_dbg(sdmmc_dev(host), "%s\n", __func__); 1018 + rtsx_usb_init_cmd(ucr); 1019 + 1020 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_EN, SD_CLK_EN, 0); 1021 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_OE, SD_OUTPUT_EN, 0); 1022 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL, 1023 + POWER_MASK, POWER_OFF); 1024 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_PWR_CTL, 1025 + POWER_MASK|LDO3318_PWR_MASK, POWER_OFF|LDO_SUSPEND); 1026 + 1027 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 1028 + if (err) 1029 + return err; 1030 + 1031 + if (CHECK_PKG(ucr, LQFP48)) 1032 + return sd_pull_ctl_disable_lqfp48(ucr); 1033 + return sd_pull_ctl_disable_qfn24(ucr); 1034 + } 1035 + 1036 + static int sd_set_power_mode(struct rtsx_usb_sdmmc *host, 1037 + unsigned char power_mode) 1038 + { 1039 + int err; 1040 + 1041 + if (power_mode != MMC_POWER_OFF) 1042 + power_mode = MMC_POWER_ON; 1043 + 1044 + if (power_mode == host->power_mode) 1045 + return 0; 1046 + 1047 + if (power_mode == MMC_POWER_OFF) { 1048 + err = sd_power_off(host); 1049 + pm_runtime_put(sdmmc_dev(host)); 1050 + } else { 1051 + pm_runtime_get_sync(sdmmc_dev(host)); 1052 + err = sd_power_on(host); 1053 + } 1054 + 1055 + if (!err) 1056 + host->power_mode = power_mode; 1057 + 1058 + return err; 1059 + } 1060 + 1061 + static int sd_set_timing(struct rtsx_usb_sdmmc *host, 1062 + unsigned char timing, bool *ddr_mode) 1063 + { 1064 + struct rtsx_ucr *ucr = host->ucr; 1065 + int err; 1066 + 1067 + *ddr_mode = false; 1068 + 1069 + rtsx_usb_init_cmd(ucr); 1070 + 1071 + switch (timing) { 1072 + case MMC_TIMING_UHS_SDR104: 1073 + case MMC_TIMING_UHS_SDR50: 1074 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG1, 1075 + 0x0C | SD_ASYNC_FIFO_RST, 1076 + SD_30_MODE | SD_ASYNC_FIFO_RST); 1077 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_SOURCE, 0xFF, 1078 + CRC_VAR_CLK0 | SD30_FIX_CLK | SAMPLE_VAR_CLK1); 1079 + break; 1080 + 1081 + case MMC_TIMING_UHS_DDR50: 1082 + *ddr_mode = true; 1083 + 1084 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG1, 1085 + 0x0C | SD_ASYNC_FIFO_RST, 1086 + SD_DDR_MODE | SD_ASYNC_FIFO_RST); 1087 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_SOURCE, 0xFF, 1088 + CRC_VAR_CLK0 | SD30_FIX_CLK | SAMPLE_VAR_CLK1); 1089 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_PUSH_POINT_CTL, 1090 + DDR_VAR_TX_CMD_DAT, DDR_VAR_TX_CMD_DAT); 1091 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_SAMPLE_POINT_CTL, 1092 + DDR_VAR_RX_DAT | DDR_VAR_RX_CMD, 1093 + DDR_VAR_RX_DAT | DDR_VAR_RX_CMD); 1094 + break; 1095 + 1096 + case MMC_TIMING_MMC_HS: 1097 + case MMC_TIMING_SD_HS: 1098 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG1, 1099 + 0x0C, SD_20_MODE); 1100 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_SOURCE, 0xFF, 1101 + CRC_FIX_CLK | SD30_VAR_CLK0 | SAMPLE_VAR_CLK1); 1102 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_PUSH_POINT_CTL, 1103 + SD20_TX_SEL_MASK, SD20_TX_14_AHEAD); 1104 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_SAMPLE_POINT_CTL, 1105 + SD20_RX_SEL_MASK, SD20_RX_14_DELAY); 1106 + break; 1107 + 1108 + default: 1109 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 1110 + SD_CFG1, 0x0C, SD_20_MODE); 1111 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_CLK_SOURCE, 0xFF, 1112 + CRC_FIX_CLK | SD30_VAR_CLK0 | SAMPLE_VAR_CLK1); 1113 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, 1114 + SD_PUSH_POINT_CTL, 0xFF, 0); 1115 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_SAMPLE_POINT_CTL, 1116 + SD20_RX_SEL_MASK, SD20_RX_POS_EDGE); 1117 + break; 1118 + } 1119 + 1120 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 1121 + 1122 + return err; 1123 + } 1124 + 1125 + static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 1126 + { 1127 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 1128 + struct rtsx_ucr *ucr = host->ucr; 1129 + 1130 + dev_dbg(sdmmc_dev(host), "%s\n", __func__); 1131 + mutex_lock(&ucr->dev_mutex); 1132 + 1133 + if (rtsx_usb_card_exclusive_check(ucr, RTSX_USB_SD_CARD)) { 1134 + mutex_unlock(&ucr->dev_mutex); 1135 + return; 1136 + } 1137 + 1138 + sd_set_power_mode(host, ios->power_mode); 1139 + sd_set_bus_width(host, ios->bus_width); 1140 + sd_set_timing(host, ios->timing, &host->ddr_mode); 1141 + 1142 + host->vpclk = false; 1143 + host->double_clk = true; 1144 + 1145 + switch (ios->timing) { 1146 + case MMC_TIMING_UHS_SDR104: 1147 + case MMC_TIMING_UHS_SDR50: 1148 + host->ssc_depth = SSC_DEPTH_2M; 1149 + host->vpclk = true; 1150 + host->double_clk = false; 1151 + break; 1152 + case MMC_TIMING_UHS_DDR50: 1153 + case MMC_TIMING_UHS_SDR25: 1154 + host->ssc_depth = SSC_DEPTH_1M; 1155 + break; 1156 + default: 1157 + host->ssc_depth = SSC_DEPTH_512K; 1158 + break; 1159 + } 1160 + 1161 + host->initial_mode = (ios->clock <= 1000000) ? true : false; 1162 + host->clock = ios->clock; 1163 + 1164 + rtsx_usb_switch_clock(host->ucr, host->clock, host->ssc_depth, 1165 + host->initial_mode, host->double_clk, host->vpclk); 1166 + 1167 + mutex_unlock(&ucr->dev_mutex); 1168 + dev_dbg(sdmmc_dev(host), "%s end\n", __func__); 1169 + } 1170 + 1171 + static int sdmmc_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios) 1172 + { 1173 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 1174 + struct rtsx_ucr *ucr = host->ucr; 1175 + int err = 0; 1176 + 1177 + dev_dbg(sdmmc_dev(host), "%s: signal_voltage = %d\n", 1178 + __func__, ios->signal_voltage); 1179 + 1180 + if (host->host_removal) 1181 + return -ENOMEDIUM; 1182 + 1183 + if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_120) 1184 + return -EPERM; 1185 + 1186 + mutex_lock(&ucr->dev_mutex); 1187 + 1188 + err = rtsx_usb_card_exclusive_check(ucr, RTSX_USB_SD_CARD); 1189 + if (err) { 1190 + mutex_unlock(&ucr->dev_mutex); 1191 + return err; 1192 + } 1193 + 1194 + /* Let mmc core do the busy checking, simply stop the forced-toggle 1195 + * clock(while issuing CMD11) and switch voltage. 1196 + */ 1197 + rtsx_usb_init_cmd(ucr); 1198 + 1199 + if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { 1200 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_PAD_CTL, 1201 + SD_IO_USING_1V8, SD_IO_USING_3V3); 1202 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, LDO_POWER_CFG, 1203 + TUNE_SD18_MASK, TUNE_SD18_3V3); 1204 + } else { 1205 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_BUS_STAT, 1206 + SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 1207 + SD_CLK_FORCE_STOP); 1208 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_PAD_CTL, 1209 + SD_IO_USING_1V8, SD_IO_USING_1V8); 1210 + rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, LDO_POWER_CFG, 1211 + TUNE_SD18_MASK, TUNE_SD18_1V8); 1212 + } 1213 + 1214 + err = rtsx_usb_send_cmd(ucr, MODE_C, 100); 1215 + mutex_unlock(&ucr->dev_mutex); 1216 + 1217 + return err; 1218 + } 1219 + 1220 + static int sdmmc_card_busy(struct mmc_host *mmc) 1221 + { 1222 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 1223 + struct rtsx_ucr *ucr = host->ucr; 1224 + int err; 1225 + u8 stat; 1226 + u8 mask = SD_DAT3_STATUS | SD_DAT2_STATUS | SD_DAT1_STATUS 1227 + | SD_DAT0_STATUS; 1228 + 1229 + dev_dbg(sdmmc_dev(host), "%s\n", __func__); 1230 + 1231 + mutex_lock(&ucr->dev_mutex); 1232 + 1233 + err = rtsx_usb_write_register(ucr, SD_BUS_STAT, 1234 + SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 1235 + SD_CLK_TOGGLE_EN); 1236 + if (err) 1237 + goto out; 1238 + 1239 + mdelay(1); 1240 + 1241 + err = rtsx_usb_read_register(ucr, SD_BUS_STAT, &stat); 1242 + if (err) 1243 + goto out; 1244 + 1245 + err = rtsx_usb_write_register(ucr, SD_BUS_STAT, 1246 + SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0); 1247 + out: 1248 + mutex_unlock(&ucr->dev_mutex); 1249 + 1250 + if (err) 1251 + return err; 1252 + 1253 + /* check if any pin between dat[0:3] is low */ 1254 + if ((stat & mask) != mask) 1255 + return 1; 1256 + else 1257 + return 0; 1258 + } 1259 + 1260 + static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode) 1261 + { 1262 + struct rtsx_usb_sdmmc *host = mmc_priv(mmc); 1263 + struct rtsx_ucr *ucr = host->ucr; 1264 + int err = 0; 1265 + 1266 + if (host->host_removal) 1267 + return -ENOMEDIUM; 1268 + 1269 + mutex_lock(&ucr->dev_mutex); 1270 + 1271 + if (!host->ddr_mode) 1272 + err = sd_tuning_rx(host, MMC_SEND_TUNING_BLOCK); 1273 + 1274 + mutex_unlock(&ucr->dev_mutex); 1275 + 1276 + return err; 1277 + } 1278 + 1279 + static const struct mmc_host_ops rtsx_usb_sdmmc_ops = { 1280 + .request = sdmmc_request, 1281 + .set_ios = sdmmc_set_ios, 1282 + .get_ro = sdmmc_get_ro, 1283 + .get_cd = sdmmc_get_cd, 1284 + .start_signal_voltage_switch = sdmmc_switch_voltage, 1285 + .card_busy = sdmmc_card_busy, 1286 + .execute_tuning = sdmmc_execute_tuning, 1287 + }; 1288 + 1289 + #ifdef RTSX_USB_USE_LEDS_CLASS 1290 + static void rtsx_usb_led_control(struct led_classdev *led, 1291 + enum led_brightness brightness) 1292 + { 1293 + struct rtsx_usb_sdmmc *host = container_of(led, 1294 + struct rtsx_usb_sdmmc, led); 1295 + 1296 + if (host->host_removal) 1297 + return; 1298 + 1299 + host->led.brightness = brightness; 1300 + schedule_work(&host->led_work); 1301 + } 1302 + 1303 + static void rtsx_usb_update_led(struct work_struct *work) 1304 + { 1305 + struct rtsx_usb_sdmmc *host = 1306 + container_of(work, struct rtsx_usb_sdmmc, led_work); 1307 + struct rtsx_ucr *ucr = host->ucr; 1308 + 1309 + mutex_lock(&ucr->dev_mutex); 1310 + 1311 + if (host->led.brightness == LED_OFF) 1312 + rtsx_usb_turn_off_led(ucr); 1313 + else 1314 + rtsx_usb_turn_on_led(ucr); 1315 + 1316 + mutex_unlock(&ucr->dev_mutex); 1317 + } 1318 + #endif 1319 + 1320 + static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host) 1321 + { 1322 + struct mmc_host *mmc = host->mmc; 1323 + 1324 + mmc->f_min = 250000; 1325 + mmc->f_max = 208000000; 1326 + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; 1327 + mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | 1328 + MMC_CAP_MMC_HIGHSPEED | MMC_CAP_BUS_WIDTH_TEST | 1329 + MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 | 1330 + MMC_CAP_NEEDS_POLL; 1331 + 1332 + mmc->max_current_330 = 400; 1333 + mmc->max_current_180 = 800; 1334 + mmc->ops = &rtsx_usb_sdmmc_ops; 1335 + mmc->max_segs = 256; 1336 + mmc->max_seg_size = 65536; 1337 + mmc->max_blk_size = 512; 1338 + mmc->max_blk_count = 65535; 1339 + mmc->max_req_size = 524288; 1340 + 1341 + host->power_mode = MMC_POWER_OFF; 1342 + } 1343 + 1344 + static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev) 1345 + { 1346 + struct mmc_host *mmc; 1347 + struct rtsx_usb_sdmmc *host; 1348 + struct rtsx_ucr *ucr; 1349 + #ifdef RTSX_USB_USE_LEDS_CLASS 1350 + int err; 1351 + #endif 1352 + 1353 + ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent)); 1354 + if (!ucr) 1355 + return -ENXIO; 1356 + 1357 + dev_dbg(&(pdev->dev), ": Realtek USB SD/MMC controller found\n"); 1358 + 1359 + mmc = mmc_alloc_host(sizeof(*host), &pdev->dev); 1360 + if (!mmc) 1361 + return -ENOMEM; 1362 + 1363 + host = mmc_priv(mmc); 1364 + host->ucr = ucr; 1365 + host->mmc = mmc; 1366 + host->pdev = pdev; 1367 + platform_set_drvdata(pdev, host); 1368 + 1369 + mutex_init(&host->host_mutex); 1370 + rtsx_usb_init_host(host); 1371 + pm_runtime_enable(&pdev->dev); 1372 + 1373 + #ifdef RTSX_USB_USE_LEDS_CLASS 1374 + snprintf(host->led_name, sizeof(host->led_name), 1375 + "%s::", mmc_hostname(mmc)); 1376 + host->led.name = host->led_name; 1377 + host->led.brightness = LED_OFF; 1378 + host->led.default_trigger = mmc_hostname(mmc); 1379 + host->led.brightness_set = rtsx_usb_led_control; 1380 + 1381 + err = led_classdev_register(mmc_dev(mmc), &host->led); 1382 + if (err) 1383 + dev_err(&(pdev->dev), 1384 + "Failed to register LED device: %d\n", err); 1385 + INIT_WORK(&host->led_work, rtsx_usb_update_led); 1386 + 1387 + #endif 1388 + mmc_add_host(mmc); 1389 + 1390 + return 0; 1391 + } 1392 + 1393 + static int rtsx_usb_sdmmc_drv_remove(struct platform_device *pdev) 1394 + { 1395 + struct rtsx_usb_sdmmc *host = platform_get_drvdata(pdev); 1396 + struct mmc_host *mmc; 1397 + 1398 + if (!host) 1399 + return 0; 1400 + 1401 + mmc = host->mmc; 1402 + host->host_removal = true; 1403 + 1404 + mutex_lock(&host->host_mutex); 1405 + if (host->mrq) { 1406 + dev_dbg(&(pdev->dev), 1407 + "%s: Controller removed during transfer\n", 1408 + mmc_hostname(mmc)); 1409 + host->mrq->cmd->error = -ENOMEDIUM; 1410 + if (host->mrq->stop) 1411 + host->mrq->stop->error = -ENOMEDIUM; 1412 + mmc_request_done(mmc, host->mrq); 1413 + } 1414 + mutex_unlock(&host->host_mutex); 1415 + 1416 + mmc_remove_host(mmc); 1417 + 1418 + #ifdef RTSX_USB_USE_LEDS_CLASS 1419 + cancel_work_sync(&host->led_work); 1420 + led_classdev_unregister(&host->led); 1421 + #endif 1422 + 1423 + mmc_free_host(mmc); 1424 + pm_runtime_disable(&pdev->dev); 1425 + platform_set_drvdata(pdev, NULL); 1426 + 1427 + dev_dbg(&(pdev->dev), 1428 + ": Realtek USB SD/MMC module has been removed\n"); 1429 + 1430 + return 0; 1431 + } 1432 + 1433 + static struct platform_device_id rtsx_usb_sdmmc_ids[] = { 1434 + { 1435 + .name = "rtsx_usb_sdmmc", 1436 + }, { 1437 + /* sentinel */ 1438 + } 1439 + }; 1440 + MODULE_DEVICE_TABLE(platform, rtsx_usb_sdmmc_ids); 1441 + 1442 + static struct platform_driver rtsx_usb_sdmmc_driver = { 1443 + .probe = rtsx_usb_sdmmc_drv_probe, 1444 + .remove = rtsx_usb_sdmmc_drv_remove, 1445 + .id_table = rtsx_usb_sdmmc_ids, 1446 + .driver = { 1447 + .owner = THIS_MODULE, 1448 + .name = "rtsx_usb_sdmmc", 1449 + }, 1450 + }; 1451 + module_platform_driver(rtsx_usb_sdmmc_driver); 1452 + 1453 + MODULE_LICENSE("GPL v2"); 1454 + MODULE_AUTHOR("Roger Tseng <rogerable@realtek.com>"); 1455 + MODULE_DESCRIPTION("Realtek USB SD/MMC Card Host Driver");
-11
drivers/power/tps65090-charger.c
··· 28 28 29 29 #include <linux/mfd/tps65090.h> 30 30 31 - #define TPS65090_REG_INTR_STS 0x00 32 - #define TPS65090_REG_INTR_MASK 0x02 33 - #define TPS65090_REG_CG_CTRL0 0x04 34 - #define TPS65090_REG_CG_CTRL1 0x05 35 - #define TPS65090_REG_CG_CTRL2 0x06 36 - #define TPS65090_REG_CG_CTRL3 0x07 37 - #define TPS65090_REG_CG_CTRL4 0x08 38 - #define TPS65090_REG_CG_CTRL5 0x09 39 - #define TPS65090_REG_CG_STATUS1 0x0a 40 - #define TPS65090_REG_CG_STATUS2 0x0b 41 - 42 31 #define TPS65090_CHARGER_ENABLE BIT(0) 43 32 #define TPS65090_VACG BIT(1) 44 33 #define TPS65090_NOITERM BIT(5)
+4 -3
drivers/regulator/Kconfig
··· 266 266 This driver supports LP8788 voltage regulator chip. 267 267 268 268 config REGULATOR_MAX14577 269 - tristate "Maxim 14577 regulator" 269 + tristate "Maxim 14577/77836 regulator" 270 270 depends on MFD_MAX14577 271 271 help 272 - This driver controls a Maxim 14577 regulator via I2C bus. 273 - The regulators include safeout LDO and current regulator 'CHARGER'. 272 + This driver controls a Maxim MAX14577/77836 regulator via I2C bus. 273 + The MAX14577 regulators include safeout LDO and charger current 274 + regulator. The MAX77836 has two additional LDOs. 274 275 275 276 config REGULATOR_MAX1586 276 277 tristate "Maxim 1586/1587 voltage regulator"
+57
drivers/regulator/arizona-ldo1.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/regulator/driver.h> 21 21 #include <linux/regulator/machine.h> 22 + #include <linux/regulator/of_regulator.h> 22 23 #include <linux/gpio.h> 23 24 #include <linux/slab.h> 24 25 ··· 179 178 .num_consumer_supplies = 1, 180 179 }; 181 180 181 + static int arizona_ldo1_of_get_pdata(struct arizona *arizona, 182 + struct regulator_config *config) 183 + { 184 + struct arizona_pdata *pdata = &arizona->pdata; 185 + struct arizona_ldo1 *ldo1 = config->driver_data; 186 + struct device_node *init_node, *dcvdd_node; 187 + struct regulator_init_data *init_data; 188 + 189 + pdata->ldoena = arizona_of_get_named_gpio(arizona, "wlf,ldoena", true); 190 + 191 + init_node = of_get_child_by_name(arizona->dev->of_node, "ldo1"); 192 + dcvdd_node = of_parse_phandle(arizona->dev->of_node, "DCVDD-supply", 0); 193 + 194 + if (init_node) { 195 + config->of_node = init_node; 196 + 197 + init_data = of_get_regulator_init_data(arizona->dev, init_node); 198 + 199 + if (init_data) { 200 + init_data->consumer_supplies = &ldo1->supply; 201 + init_data->num_consumer_supplies = 1; 202 + 203 + if (dcvdd_node && dcvdd_node != init_node) 204 + arizona->external_dcvdd = true; 205 + 206 + pdata->ldo1 = init_data; 207 + } 208 + } else if (dcvdd_node) { 209 + arizona->external_dcvdd = true; 210 + } 211 + 212 + of_node_put(dcvdd_node); 213 + 214 + return 0; 215 + } 216 + 182 217 static int arizona_ldo1_probe(struct platform_device *pdev) 183 218 { 184 219 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); ··· 222 185 struct regulator_config config = { }; 223 186 struct arizona_ldo1 *ldo1; 224 187 int ret; 188 + 189 + arizona->external_dcvdd = false; 225 190 226 191 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); 227 192 if (!ldo1) ··· 255 216 config.dev = arizona->dev; 256 217 config.driver_data = ldo1; 257 218 config.regmap = arizona->regmap; 219 + 220 + if (IS_ENABLED(CONFIG_OF)) { 221 + if (!dev_get_platdata(arizona->dev)) { 222 + ret = arizona_ldo1_of_get_pdata(arizona, &config); 223 + if (ret < 0) 224 + return ret; 225 + } 226 + } 227 + 258 228 config.ena_gpio = arizona->pdata.ldoena; 259 229 260 230 if (arizona->pdata.ldo1) 261 231 config.init_data = arizona->pdata.ldo1; 262 232 else 263 233 config.init_data = &ldo1->init_data; 234 + 235 + /* 236 + * LDO1 can only be used to supply DCVDD so if it has no 237 + * consumers then DCVDD is supplied externally. 238 + */ 239 + if (config.init_data->num_consumer_supplies == 0) 240 + arizona->external_dcvdd = true; 264 241 265 242 ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config); 266 243 if (IS_ERR(ldo1->regulator)) { ··· 285 230 ret); 286 231 return ret; 287 232 } 233 + 234 + of_node_put(config.of_node); 288 235 289 236 platform_set_drvdata(pdev, ldo1); 290 237
+37
drivers/regulator/arizona-micsupp.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/regulator/driver.h> 21 21 #include <linux/regulator/machine.h> 22 + #include <linux/regulator/of_regulator.h> 22 23 #include <linux/gpio.h> 23 24 #include <linux/slab.h> 24 25 #include <linux/workqueue.h> ··· 196 195 .num_consumer_supplies = 1, 197 196 }; 198 197 198 + static int arizona_micsupp_of_get_pdata(struct arizona *arizona, 199 + struct regulator_config *config) 200 + { 201 + struct arizona_pdata *pdata = &arizona->pdata; 202 + struct arizona_micsupp *micsupp = config->driver_data; 203 + struct device_node *np; 204 + struct regulator_init_data *init_data; 205 + 206 + np = of_get_child_by_name(arizona->dev->of_node, "micvdd"); 207 + 208 + if (np) { 209 + config->of_node = np; 210 + 211 + init_data = of_get_regulator_init_data(arizona->dev, np); 212 + 213 + if (init_data) { 214 + init_data->consumer_supplies = &micsupp->supply; 215 + init_data->num_consumer_supplies = 1; 216 + 217 + pdata->micvdd = init_data; 218 + } 219 + } 220 + 221 + return 0; 222 + } 223 + 199 224 static int arizona_micsupp_probe(struct platform_device *pdev) 200 225 { 201 226 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); ··· 261 234 config.driver_data = micsupp; 262 235 config.regmap = arizona->regmap; 263 236 237 + if (IS_ENABLED(CONFIG_OF)) { 238 + if (!dev_get_platdata(arizona->dev)) { 239 + ret = arizona_micsupp_of_get_pdata(arizona, &config); 240 + if (ret < 0) 241 + return ret; 242 + } 243 + } 244 + 264 245 if (arizona->pdata.micvdd) 265 246 config.init_data = arizona->pdata.micvdd; 266 247 else ··· 287 252 ret); 288 253 return ret; 289 254 } 255 + 256 + of_node_put(config.of_node); 290 257 291 258 platform_set_drvdata(pdev, micsupp); 292 259
+243 -36
drivers/regulator/max14577.c
··· 1 1 /* 2 - * max14577.c - Regulator driver for the Maxim 14577 2 + * max14577.c - Regulator driver for the Maxim 14577/77836 3 3 * 4 4 * Copyright (C) 2013,2014 Samsung Electronics 5 5 * Krzysztof Kozlowski <k.kozlowski@samsung.com> ··· 21 21 #include <linux/mfd/max14577.h> 22 22 #include <linux/mfd/max14577-private.h> 23 23 #include <linux/regulator/of_regulator.h> 24 + 25 + /* 26 + * Valid limits of current for max14577 and max77836 chargers. 27 + * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4 28 + * register for given chipset. 29 + */ 30 + struct maxim_charger_current { 31 + /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */ 32 + unsigned int min; 33 + /* 34 + * Minimal current when high setting is active, 35 + * set in CHGCTRL4/MBCICHWRCH, uA 36 + */ 37 + unsigned int high_start; 38 + /* Value of one step in high setting, uA */ 39 + unsigned int high_step; 40 + /* Maximum current of high setting, uA */ 41 + unsigned int max; 42 + }; 43 + 44 + /* Table of valid charger currents for different Maxim chipsets */ 45 + static const struct maxim_charger_current maxim_charger_currents[] = { 46 + [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 }, 47 + [MAXIM_DEVICE_TYPE_MAX14577] = { 48 + .min = MAX14577_REGULATOR_CURRENT_LIMIT_MIN, 49 + .high_start = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START, 50 + .high_step = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP, 51 + .max = MAX14577_REGULATOR_CURRENT_LIMIT_MAX, 52 + }, 53 + [MAXIM_DEVICE_TYPE_MAX77836] = { 54 + .min = MAX77836_REGULATOR_CURRENT_LIMIT_MIN, 55 + .high_start = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START, 56 + .high_step = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP, 57 + .max = MAX77836_REGULATOR_CURRENT_LIMIT_MAX, 58 + }, 59 + }; 24 60 25 61 static int max14577_reg_is_enabled(struct regulator_dev *rdev) 26 62 { ··· 83 47 { 84 48 u8 reg_data; 85 49 struct regmap *rmap = rdev->regmap; 50 + struct max14577 *max14577 = rdev_get_drvdata(rdev); 51 + const struct maxim_charger_current *limits = 52 + &maxim_charger_currents[max14577->dev_type]; 86 53 87 54 if (rdev_get_id(rdev) != MAX14577_CHARGER) 88 55 return -EINVAL; ··· 93 54 max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, &reg_data); 94 55 95 56 if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0) 96 - return MAX14577_REGULATOR_CURRENT_LIMIT_MIN; 57 + return limits->min; 97 58 98 59 reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >> 99 60 CHGCTRL4_MBCICHWRCH_SHIFT); 100 - return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + 101 - reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP; 61 + return limits->high_start + reg_data * limits->high_step; 102 62 } 103 63 104 64 static int max14577_reg_set_current_limit(struct regulator_dev *rdev, ··· 105 67 { 106 68 int i, current_bits = 0xf; 107 69 u8 reg_data; 70 + struct max14577 *max14577 = rdev_get_drvdata(rdev); 71 + const struct maxim_charger_current *limits = 72 + &maxim_charger_currents[max14577->dev_type]; 108 73 109 74 if (rdev_get_id(rdev) != MAX14577_CHARGER) 110 75 return -EINVAL; 111 76 112 - if (min_uA > MAX14577_REGULATOR_CURRENT_LIMIT_MAX || 113 - max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_MIN) 77 + if (min_uA > limits->max || max_uA < limits->min) 114 78 return -EINVAL; 115 79 116 - if (max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START) { 117 - /* Less than 200 mA, so set 90mA (turn only Low Bit off) */ 80 + if (max_uA < limits->high_start) { 81 + /* 82 + * Less than high_start, 83 + * so set the minimal current (turn only Low Bit off) 84 + */ 118 85 u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT; 119 86 return max14577_update_reg(rdev->regmap, 120 87 MAX14577_CHG_REG_CHG_CTRL4, 121 88 CHGCTRL4_MBCICHWRCL_MASK, reg_data); 122 89 } 123 90 124 - /* max_uA is in range: <LIMIT_HIGH_START, inifinite>, so search for 125 - * valid current starting from LIMIT_MAX. */ 126 - for (i = MAX14577_REGULATOR_CURRENT_LIMIT_MAX; 127 - i >= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START; 128 - i -= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP) { 91 + /* 92 + * max_uA is in range: <high_start, inifinite>, so search for 93 + * valid current starting from maximum current. 94 + */ 95 + for (i = limits->max; i >= limits->high_start; i -= limits->high_step) { 129 96 if (i <= max_uA) 130 97 break; 131 98 current_bits--; 132 99 } 133 100 BUG_ON(current_bits < 0); /* Cannot happen */ 134 - /* Turn Low Bit on (use range 200mA-950 mA) */ 101 + 102 + /* Turn Low Bit on (use range high_start-max)... */ 135 103 reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; 136 104 /* and set proper High Bits */ 137 105 reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; ··· 162 118 .set_current_limit = max14577_reg_set_current_limit, 163 119 }; 164 120 165 - static const struct regulator_desc supported_regulators[] = { 121 + static const struct regulator_desc max14577_supported_regulators[] = { 166 122 [MAX14577_SAFEOUT] = { 167 123 .name = "SAFEOUT", 168 124 .id = MAX14577_SAFEOUT, ··· 185 141 }, 186 142 }; 187 143 144 + static struct regulator_ops max77836_ldo_ops = { 145 + .is_enabled = regulator_is_enabled_regmap, 146 + .enable = regulator_enable_regmap, 147 + .disable = regulator_disable_regmap, 148 + .list_voltage = regulator_list_voltage_linear, 149 + .map_voltage = regulator_map_voltage_linear, 150 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 151 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 152 + /* TODO: add .set_suspend_mode */ 153 + }; 154 + 155 + static const struct regulator_desc max77836_supported_regulators[] = { 156 + [MAX14577_SAFEOUT] = { 157 + .name = "SAFEOUT", 158 + .id = MAX14577_SAFEOUT, 159 + .ops = &max14577_safeout_ops, 160 + .type = REGULATOR_VOLTAGE, 161 + .owner = THIS_MODULE, 162 + .n_voltages = 1, 163 + .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE, 164 + .enable_reg = MAX14577_REG_CONTROL2, 165 + .enable_mask = CTRL2_SFOUTORD_MASK, 166 + }, 167 + [MAX14577_CHARGER] = { 168 + .name = "CHARGER", 169 + .id = MAX14577_CHARGER, 170 + .ops = &max14577_charger_ops, 171 + .type = REGULATOR_CURRENT, 172 + .owner = THIS_MODULE, 173 + .enable_reg = MAX14577_CHG_REG_CHG_CTRL2, 174 + .enable_mask = CHGCTRL2_MBCHOSTEN_MASK, 175 + }, 176 + [MAX77836_LDO1] = { 177 + .name = "LDO1", 178 + .id = MAX77836_LDO1, 179 + .ops = &max77836_ldo_ops, 180 + .type = REGULATOR_VOLTAGE, 181 + .owner = THIS_MODULE, 182 + .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM, 183 + .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN, 184 + .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP, 185 + .enable_reg = MAX77836_LDO_REG_CNFG1_LDO1, 186 + .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK, 187 + .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO1, 188 + .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK, 189 + }, 190 + [MAX77836_LDO2] = { 191 + .name = "LDO2", 192 + .id = MAX77836_LDO2, 193 + .ops = &max77836_ldo_ops, 194 + .type = REGULATOR_VOLTAGE, 195 + .owner = THIS_MODULE, 196 + .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM, 197 + .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN, 198 + .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP, 199 + .enable_reg = MAX77836_LDO_REG_CNFG1_LDO2, 200 + .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK, 201 + .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO2, 202 + .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK, 203 + }, 204 + }; 205 + 188 206 #ifdef CONFIG_OF 189 207 static struct of_regulator_match max14577_regulator_matches[] = { 190 208 { .name = "SAFEOUT", }, 191 209 { .name = "CHARGER", }, 192 210 }; 193 211 194 - static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) 212 + static struct of_regulator_match max77836_regulator_matches[] = { 213 + { .name = "SAFEOUT", }, 214 + { .name = "CHARGER", }, 215 + { .name = "LDO1", }, 216 + { .name = "LDO2", }, 217 + }; 218 + 219 + static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev, 220 + enum maxim_device_type dev_type) 195 221 { 196 222 int ret; 197 223 struct device_node *np; 224 + struct of_regulator_match *regulator_matches; 225 + unsigned int regulator_matches_size; 198 226 199 227 np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); 200 228 if (!np) { ··· 274 158 return -EINVAL; 275 159 } 276 160 277 - ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches, 278 - MAX14577_REG_MAX); 161 + switch (dev_type) { 162 + case MAXIM_DEVICE_TYPE_MAX77836: 163 + regulator_matches = max77836_regulator_matches; 164 + regulator_matches_size = ARRAY_SIZE(max77836_regulator_matches); 165 + break; 166 + case MAXIM_DEVICE_TYPE_MAX14577: 167 + default: 168 + regulator_matches = max14577_regulator_matches; 169 + regulator_matches_size = ARRAY_SIZE(max14577_regulator_matches); 170 + } 171 + 172 + ret = of_regulator_match(&pdev->dev, np, regulator_matches, 173 + regulator_matches_size); 279 174 if (ret < 0) 280 175 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); 281 176 else ··· 297 170 return ret; 298 171 } 299 172 300 - static inline struct regulator_init_data *match_init_data(int index) 173 + static inline struct regulator_init_data *match_init_data(int index, 174 + enum maxim_device_type dev_type) 301 175 { 302 - return max14577_regulator_matches[index].init_data; 176 + switch (dev_type) { 177 + case MAXIM_DEVICE_TYPE_MAX77836: 178 + return max77836_regulator_matches[index].init_data; 179 + 180 + case MAXIM_DEVICE_TYPE_MAX14577: 181 + default: 182 + return max14577_regulator_matches[index].init_data; 183 + } 303 184 } 304 185 305 - static inline struct device_node *match_of_node(int index) 186 + static inline struct device_node *match_of_node(int index, 187 + enum maxim_device_type dev_type) 306 188 { 307 - return max14577_regulator_matches[index].of_node; 189 + switch (dev_type) { 190 + case MAXIM_DEVICE_TYPE_MAX77836: 191 + return max77836_regulator_matches[index].of_node; 192 + 193 + case MAXIM_DEVICE_TYPE_MAX14577: 194 + default: 195 + return max14577_regulator_matches[index].of_node; 196 + } 308 197 } 309 198 #else /* CONFIG_OF */ 310 - static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) 199 + static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev, 200 + enum maxim_device_type dev_type) 311 201 { 312 202 return 0; 313 203 } 314 - static inline struct regulator_init_data *match_init_data(int index) 204 + static inline struct regulator_init_data *match_init_data(int index, 205 + enum maxim_device_type dev_type) 315 206 { 316 207 return NULL; 317 208 } 318 209 319 - static inline struct device_node *match_of_node(int index) 210 + static inline struct device_node *match_of_node(int index, 211 + enum maxim_device_type dev_type) 320 212 { 321 213 return NULL; 322 214 } 323 215 #endif /* CONFIG_OF */ 324 216 217 + /** 218 + * Registers for regulators of max77836 use different I2C slave addresses so 219 + * different regmaps must be used for them. 220 + * 221 + * Returns proper regmap for accessing regulator passed by id. 222 + */ 223 + static struct regmap *max14577_get_regmap(struct max14577 *max14577, 224 + int reg_id) 225 + { 226 + switch (max14577->dev_type) { 227 + case MAXIM_DEVICE_TYPE_MAX77836: 228 + switch (reg_id) { 229 + case MAX77836_SAFEOUT ... MAX77836_CHARGER: 230 + return max14577->regmap; 231 + default: 232 + /* MAX77836_LDO1 ... MAX77836_LDO2 */ 233 + return max14577->regmap_pmic; 234 + } 235 + 236 + case MAXIM_DEVICE_TYPE_MAX14577: 237 + default: 238 + return max14577->regmap; 239 + } 240 + } 325 241 326 242 static int max14577_regulator_probe(struct platform_device *pdev) 327 243 { ··· 372 202 struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev); 373 203 int i, ret; 374 204 struct regulator_config config = {}; 205 + const struct regulator_desc *supported_regulators; 206 + unsigned int supported_regulators_size; 207 + enum maxim_device_type dev_type = max14577->dev_type; 375 208 376 - ret = max14577_regulator_dt_parse_pdata(pdev); 209 + ret = max14577_regulator_dt_parse_pdata(pdev, dev_type); 377 210 if (ret) 378 211 return ret; 379 212 380 - config.dev = &pdev->dev; 381 - config.regmap = max14577->regmap; 213 + switch (dev_type) { 214 + case MAXIM_DEVICE_TYPE_MAX77836: 215 + supported_regulators = max77836_supported_regulators; 216 + supported_regulators_size = ARRAY_SIZE(max77836_supported_regulators); 217 + break; 218 + case MAXIM_DEVICE_TYPE_MAX14577: 219 + default: 220 + supported_regulators = max14577_supported_regulators; 221 + supported_regulators_size = ARRAY_SIZE(max14577_supported_regulators); 222 + } 382 223 383 - for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) { 224 + config.dev = &pdev->dev; 225 + config.driver_data = max14577; 226 + 227 + for (i = 0; i < supported_regulators_size; i++) { 384 228 struct regulator_dev *regulator; 385 229 /* 386 230 * Index of supported_regulators[] is also the id and must ··· 404 220 config.init_data = pdata->regulators[i].initdata; 405 221 config.of_node = pdata->regulators[i].of_node; 406 222 } else { 407 - config.init_data = match_init_data(i); 408 - config.of_node = match_of_node(i); 223 + config.init_data = match_init_data(i, dev_type); 224 + config.of_node = match_of_node(i, dev_type); 409 225 } 226 + config.regmap = max14577_get_regmap(max14577, 227 + supported_regulators[i].id); 410 228 411 229 regulator = devm_regulator_register(&pdev->dev, 412 230 &supported_regulators[i], &config); 413 231 if (IS_ERR(regulator)) { 414 232 ret = PTR_ERR(regulator); 415 233 dev_err(&pdev->dev, 416 - "Regulator init failed for ID %d with error: %d\n", 417 - i, ret); 234 + "Regulator init failed for %d/%s with error: %d\n", 235 + i, supported_regulators[i].name, ret); 418 236 return ret; 419 237 } 420 238 } ··· 424 238 return ret; 425 239 } 426 240 241 + static const struct platform_device_id max14577_regulator_id[] = { 242 + { "max14577-regulator", MAXIM_DEVICE_TYPE_MAX14577, }, 243 + { "max77836-regulator", MAXIM_DEVICE_TYPE_MAX77836, }, 244 + { } 245 + }; 246 + MODULE_DEVICE_TABLE(platform, max14577_regulator_id); 247 + 427 248 static struct platform_driver max14577_regulator_driver = { 428 249 .driver = { 429 250 .owner = THIS_MODULE, 430 251 .name = "max14577-regulator", 431 252 }, 432 - .probe = max14577_regulator_probe, 253 + .probe = max14577_regulator_probe, 254 + .id_table = max14577_regulator_id, 433 255 }; 434 256 435 257 static int __init max14577_regulator_init(void) 436 258 { 259 + /* Check for valid values for charger */ 437 260 BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + 438 261 MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != 439 262 MAX14577_REGULATOR_CURRENT_LIMIT_MAX); 440 - BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_MAX); 263 + BUILD_BUG_ON(MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START + 264 + MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != 265 + MAX77836_REGULATOR_CURRENT_LIMIT_MAX); 266 + /* Valid charger current values must be provided for each chipset */ 267 + BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM); 268 + 269 + BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REGULATOR_NUM); 270 + BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REGULATOR_NUM); 271 + 272 + BUILD_BUG_ON(MAX77836_REGULATOR_LDO_VOLTAGE_MIN + 273 + (MAX77836_REGULATOR_LDO_VOLTAGE_STEP * 274 + (MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM - 1)) != 275 + MAX77836_REGULATOR_LDO_VOLTAGE_MAX); 441 276 442 277 return platform_driver_register(&max14577_regulator_driver); 443 278 } ··· 471 264 module_exit(max14577_regulator_exit); 472 265 473 266 MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 474 - MODULE_DESCRIPTION("MAXIM 14577 regulator driver"); 267 + MODULE_DESCRIPTION("Maxim 14577/77836 regulator driver"); 475 268 MODULE_LICENSE("GPL"); 476 269 MODULE_ALIAS("platform:max14577-regulator");
+58 -5
drivers/regulator/tps6586x-regulator.c
··· 68 68 return rdev_get_dev(rdev)->parent; 69 69 } 70 70 71 - static struct regulator_ops tps6586x_regulator_ops = { 71 + static struct regulator_ops tps6586x_rw_regulator_ops = { 72 72 .list_voltage = regulator_list_voltage_table, 73 73 .map_voltage = regulator_map_voltage_ascend, 74 74 .get_voltage_sel = regulator_get_voltage_sel_regmap, 75 75 .set_voltage_sel = regulator_set_voltage_sel_regmap, 76 + 77 + .is_enabled = regulator_is_enabled_regmap, 78 + .enable = regulator_enable_regmap, 79 + .disable = regulator_disable_regmap, 80 + }; 81 + 82 + static struct regulator_ops tps6586x_ro_regulator_ops = { 83 + .list_voltage = regulator_list_voltage_table, 84 + .map_voltage = regulator_map_voltage_ascend, 85 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 76 86 77 87 .is_enabled = regulator_is_enabled_regmap, 78 88 .enable = regulator_enable_regmap, ··· 116 106 4200000, 4250000, 4300000, 4350000, 4400000, 4450000, 4500000, 4550000, 117 107 }; 118 108 109 + static int tps658640_sm2_voltages[] = { 110 + 2150000, 2200000, 2250000, 2300000, 2350000, 2400000, 2450000, 2500000, 111 + 2550000, 2600000, 2650000, 2700000, 2750000, 2800000, 2850000, 2900000, 112 + 2950000, 3000000, 3050000, 3100000, 3150000, 3200000, 3250000, 3300000, 113 + 3350000, 3400000, 3450000, 3500000, 3550000, 3600000, 3650000, 3700000, 114 + }; 115 + 119 116 static const unsigned int tps658643_sm2_voltages[] = { 120 117 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 121 118 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000, ··· 137 120 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, 138 121 }; 139 122 140 - #define TPS6586X_REGULATOR(_id, _pin_name, vdata, vreg, shift, nbits, \ 123 + static int tps658640_rtc_voltages[] = { 124 + 2500000, 2850000, 3100000, 3300000, 125 + }; 126 + 127 + #define TPS6586X_REGULATOR(_id, _ops, _pin_name, vdata, vreg, shift, nbits, \ 141 128 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 142 129 .desc = { \ 143 130 .supply_name = _pin_name, \ 144 131 .name = "REG-" #_id, \ 145 - .ops = &tps6586x_regulator_ops, \ 132 + .ops = &tps6586x_## _ops ## _regulator_ops, \ 146 133 .type = REGULATOR_VOLTAGE, \ 147 134 .id = TPS6586X_ID_##_id, \ 148 135 .n_voltages = ARRAY_SIZE(vdata##_voltages), \ ··· 167 146 #define TPS6586X_LDO(_id, _pname, vdata, vreg, shift, nbits, \ 168 147 ereg0, ebit0, ereg1, ebit1) \ 169 148 { \ 170 - TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \ 149 + TPS6586X_REGULATOR(_id, rw, _pname, vdata, vreg, shift, nbits, \ 150 + ereg0, ebit0, ereg1, ebit1, 0, 0) \ 151 + } 152 + 153 + #define TPS6586X_FIXED_LDO(_id, _pname, vdata, vreg, shift, nbits, \ 154 + ereg0, ebit0, ereg1, ebit1) \ 155 + { \ 156 + TPS6586X_REGULATOR(_id, ro, _pname, vdata, vreg, shift, nbits, \ 171 157 ereg0, ebit0, ereg1, ebit1, 0, 0) \ 172 158 } 173 159 174 160 #define TPS6586X_DVM(_id, _pname, vdata, vreg, shift, nbits, \ 175 161 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 176 162 { \ 177 - TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \ 163 + TPS6586X_REGULATOR(_id, rw, _pname, vdata, vreg, shift, nbits, \ 178 164 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ 179 165 } 180 166 ··· 233 205 static struct tps6586x_regulator tps658623_regulator[] = { 234 206 TPS6586X_LDO(SM_2, "vin-sm2", tps658623_sm2, SUPPLYV2, 0, 5, ENC, 7, 235 207 END, 7), 208 + }; 209 + 210 + static struct tps6586x_regulator tps658640_regulator[] = { 211 + TPS6586X_LDO(LDO_3, "vinldo23", tps6586x_ldo0, SUPPLYV4, 0, 3, 212 + ENC, 2, END, 2), 213 + TPS6586X_LDO(LDO_5, "REG-SYS", tps6586x_ldo0, SUPPLYV6, 0, 3, 214 + ENE, 6, ENE, 6), 215 + TPS6586X_LDO(LDO_6, "vinldo678", tps6586x_ldo0, SUPPLYV3, 0, 3, 216 + ENC, 4, END, 4), 217 + TPS6586X_LDO(LDO_7, "vinldo678", tps6586x_ldo0, SUPPLYV3, 3, 3, 218 + ENC, 5, END, 5), 219 + TPS6586X_LDO(LDO_8, "vinldo678", tps6586x_ldo0, SUPPLYV2, 5, 3, 220 + ENC, 6, END, 6), 221 + TPS6586X_LDO(LDO_9, "vinldo9", tps6586x_ldo0, SUPPLYV6, 3, 3, 222 + ENE, 7, ENE, 7), 223 + TPS6586X_LDO(SM_2, "vin-sm2", tps658640_sm2, SUPPLYV2, 0, 5, 224 + ENC, 7, END, 7), 225 + 226 + TPS6586X_FIXED_LDO(LDO_RTC, "REG-SYS", tps658640_rtc, SUPPLYV4, 3, 2, 227 + V4, 7, V4, 7), 236 228 }; 237 229 238 230 static struct tps6586x_regulator tps658643_regulator[] = { ··· 342 294 case TPS658623: 343 295 table = tps658623_regulator; 344 296 num = ARRAY_SIZE(tps658623_regulator); 297 + break; 298 + case TPS658640: 299 + case TPS658640v2: 300 + table = tps658640_regulator; 301 + num = ARRAY_SIZE(tps658640_regulator); 345 302 break; 346 303 case TPS658643: 347 304 table = tps658643_regulator;
+21
include/linux/cpufreq.h
··· 468 468 * order */ 469 469 }; 470 470 471 + bool cpufreq_next_valid(struct cpufreq_frequency_table **pos); 472 + 473 + /* 474 + * cpufreq_for_each_entry - iterate over a cpufreq_frequency_table 475 + * @pos: the cpufreq_frequency_table * to use as a loop cursor. 476 + * @table: the cpufreq_frequency_table * to iterate over. 477 + */ 478 + 479 + #define cpufreq_for_each_entry(pos, table) \ 480 + for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++) 481 + 482 + /* 483 + * cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table 484 + * excluding CPUFREQ_ENTRY_INVALID frequencies. 485 + * @pos: the cpufreq_frequency_table * to use as a loop cursor. 486 + * @table: the cpufreq_frequency_table * to iterate over. 487 + */ 488 + 489 + #define cpufreq_for_each_valid_entry(pos, table) \ 490 + for (pos = table; cpufreq_next_valid(&pos); pos++) 491 + 471 492 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 472 493 struct cpufreq_frequency_table *table); 473 494
+3
include/linux/mfd/arizona/core.h
··· 124 124 int wm5110_patch(struct arizona *arizona); 125 125 int wm8997_patch(struct arizona *arizona); 126 126 127 + extern int arizona_of_get_named_gpio(struct arizona *arizona, const char *prop, 128 + bool mandatory); 129 + 127 130 #endif
+168 -50
include/linux/mfd/max14577-private.h
··· 1 1 /* 2 - * max14577-private.h - Common API for the Maxim 14577 internal sub chip 2 + * max14577-private.h - Common API for the Maxim 14577/77836 internal sub chip 3 3 * 4 - * Copyright (C) 2013 Samsung Electrnoics 4 + * Copyright (C) 2014 Samsung Electrnoics 5 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 7 7 * ··· 22 22 #include <linux/i2c.h> 23 23 #include <linux/regmap.h> 24 24 25 - #define MAX14577_REG_INVALID (0xff) 25 + #define I2C_ADDR_PMIC (0x46 >> 1) 26 + #define I2C_ADDR_MUIC (0x4A >> 1) 27 + #define I2C_ADDR_FG (0x6C >> 1) 26 28 27 - /* Slave addr = 0x4A: Interrupt */ 29 + enum maxim_device_type { 30 + MAXIM_DEVICE_TYPE_UNKNOWN = 0, 31 + MAXIM_DEVICE_TYPE_MAX14577, 32 + MAXIM_DEVICE_TYPE_MAX77836, 33 + 34 + MAXIM_DEVICE_TYPE_NUM, 35 + }; 36 + 37 + /* Slave addr = 0x4A: MUIC and Charger */ 28 38 enum max14577_reg { 29 39 MAX14577_REG_DEVICEID = 0x00, 30 40 MAX14577_REG_INT1 = 0x01, ··· 84 74 }; 85 75 86 76 /* MAX14577 interrupts */ 87 - #define INT1_ADC_MASK (0x1 << 0) 88 - #define INT1_ADCLOW_MASK (0x1 << 1) 89 - #define INT1_ADCERR_MASK (0x1 << 2) 77 + #define MAX14577_INT1_ADC_MASK BIT(0) 78 + #define MAX14577_INT1_ADCLOW_MASK BIT(1) 79 + #define MAX14577_INT1_ADCERR_MASK BIT(2) 80 + #define MAX77836_INT1_ADC1K_MASK BIT(3) 90 81 91 - #define INT2_CHGTYP_MASK (0x1 << 0) 92 - #define INT2_CHGDETRUN_MASK (0x1 << 1) 93 - #define INT2_DCDTMR_MASK (0x1 << 2) 94 - #define INT2_DBCHG_MASK (0x1 << 3) 95 - #define INT2_VBVOLT_MASK (0x1 << 4) 82 + #define MAX14577_INT2_CHGTYP_MASK BIT(0) 83 + #define MAX14577_INT2_CHGDETRUN_MASK BIT(1) 84 + #define MAX14577_INT2_DCDTMR_MASK BIT(2) 85 + #define MAX14577_INT2_DBCHG_MASK BIT(3) 86 + #define MAX14577_INT2_VBVOLT_MASK BIT(4) 87 + #define MAX77836_INT2_VIDRM_MASK BIT(5) 96 88 97 - #define INT3_EOC_MASK (0x1 << 0) 98 - #define INT3_CGMBC_MASK (0x1 << 1) 99 - #define INT3_OVP_MASK (0x1 << 2) 100 - #define INT3_MBCCHGERR_MASK (0x1 << 3) 89 + #define MAX14577_INT3_EOC_MASK BIT(0) 90 + #define MAX14577_INT3_CGMBC_MASK BIT(1) 91 + #define MAX14577_INT3_OVP_MASK BIT(2) 92 + #define MAX14577_INT3_MBCCHGERR_MASK BIT(3) 101 93 102 94 /* MAX14577 DEVICE ID register */ 103 95 #define DEVID_VENDORID_SHIFT 0 ··· 111 99 #define STATUS1_ADC_SHIFT 0 112 100 #define STATUS1_ADCLOW_SHIFT 5 113 101 #define STATUS1_ADCERR_SHIFT 6 102 + #define MAX77836_STATUS1_ADC1K_SHIFT 7 114 103 #define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT) 115 - #define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT) 116 - #define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT) 104 + #define STATUS1_ADCLOW_MASK BIT(STATUS1_ADCLOW_SHIFT) 105 + #define STATUS1_ADCERR_MASK BIT(STATUS1_ADCERR_SHIFT) 106 + #define MAX77836_STATUS1_ADC1K_MASK BIT(MAX77836_STATUS1_ADC1K_SHIFT) 117 107 118 108 /* MAX14577 STATUS2 register */ 119 109 #define STATUS2_CHGTYP_SHIFT 0 ··· 123 109 #define STATUS2_DCDTMR_SHIFT 4 124 110 #define STATUS2_DBCHG_SHIFT 5 125 111 #define STATUS2_VBVOLT_SHIFT 6 112 + #define MAX77836_STATUS2_VIDRM_SHIFT 7 126 113 #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) 127 - #define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT) 128 - #define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT) 129 - #define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT) 130 - #define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT) 114 + #define STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) 115 + #define STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) 116 + #define STATUS2_DBCHG_MASK BIT(STATUS2_DBCHG_SHIFT) 117 + #define STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) 118 + #define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT) 131 119 132 120 /* MAX14577 CONTROL1 register */ 133 121 #define COMN1SW_SHIFT 0 ··· 138 122 #define IDBEN_SHIFT 7 139 123 #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) 140 124 #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) 141 - #define MICEN_MASK (0x1 << MICEN_SHIFT) 142 - #define IDBEN_MASK (0x1 << IDBEN_SHIFT) 125 + #define MICEN_MASK BIT(MICEN_SHIFT) 126 + #define IDBEN_MASK BIT(IDBEN_SHIFT) 143 127 #define CLEAR_IDBEN_MICEN_MASK (COMN1SW_MASK | COMP2SW_MASK) 144 128 #define CTRL1_SW_USB ((1 << COMP2SW_SHIFT) \ 145 129 | (1 << COMN1SW_SHIFT)) ··· 159 143 #define CTRL2_ACCDET_SHIFT (5) 160 144 #define CTRL2_USBCPINT_SHIFT (6) 161 145 #define CTRL2_RCPS_SHIFT (7) 162 - #define CTRL2_LOWPWR_MASK (0x1 << CTRL2_LOWPWR_SHIFT) 163 - #define CTRL2_ADCEN_MASK (0x1 << CTRL2_ADCEN_SHIFT) 164 - #define CTRL2_CPEN_MASK (0x1 << CTRL2_CPEN_SHIFT) 165 - #define CTRL2_SFOUTASRT_MASK (0x1 << CTRL2_SFOUTASRT_SHIFT) 166 - #define CTRL2_SFOUTORD_MASK (0x1 << CTRL2_SFOUTORD_SHIFT) 167 - #define CTRL2_ACCDET_MASK (0x1 << CTRL2_ACCDET_SHIFT) 168 - #define CTRL2_USBCPINT_MASK (0x1 << CTRL2_USBCPINT_SHIFT) 169 - #define CTRL2_RCPS_MASK (0x1 << CTR2_RCPS_SHIFT) 146 + #define CTRL2_LOWPWR_MASK BIT(CTRL2_LOWPWR_SHIFT) 147 + #define CTRL2_ADCEN_MASK BIT(CTRL2_ADCEN_SHIFT) 148 + #define CTRL2_CPEN_MASK BIT(CTRL2_CPEN_SHIFT) 149 + #define CTRL2_SFOUTASRT_MASK BIT(CTRL2_SFOUTASRT_SHIFT) 150 + #define CTRL2_SFOUTORD_MASK BIT(CTRL2_SFOUTORD_SHIFT) 151 + #define CTRL2_ACCDET_MASK BIT(CTRL2_ACCDET_SHIFT) 152 + #define CTRL2_USBCPINT_MASK BIT(CTRL2_USBCPINT_SHIFT) 153 + #define CTRL2_RCPS_MASK BIT(CTRL2_RCPS_SHIFT) 170 154 171 155 #define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \ 172 156 (0 << CTRL2_LOWPWR_SHIFT)) ··· 214 198 #define CDETCTRL1_DBEXIT_SHIFT 5 215 199 #define CDETCTRL1_DBIDLE_SHIFT 6 216 200 #define CDETCTRL1_CDPDET_SHIFT 7 217 - #define CDETCTRL1_CHGDETEN_MASK (0x1 << CDETCTRL1_CHGDETEN_SHIFT) 218 - #define CDETCTRL1_CHGTYPMAN_MASK (0x1 << CDETCTRL1_CHGTYPMAN_SHIFT) 219 - #define CDETCTRL1_DCDEN_MASK (0x1 << CDETCTRL1_DCDEN_SHIFT) 220 - #define CDETCTRL1_DCD2SCT_MASK (0x1 << CDETCTRL1_DCD2SCT_SHIFT) 221 - #define CDETCTRL1_DCHKTM_MASK (0x1 << CDETCTRL1_DCHKTM_SHIFT) 222 - #define CDETCTRL1_DBEXIT_MASK (0x1 << CDETCTRL1_DBEXIT_SHIFT) 223 - #define CDETCTRL1_DBIDLE_MASK (0x1 << CDETCTRL1_DBIDLE_SHIFT) 224 - #define CDETCTRL1_CDPDET_MASK (0x1 << CDETCTRL1_CDPDET_SHIFT) 201 + #define CDETCTRL1_CHGDETEN_MASK BIT(CDETCTRL1_CHGDETEN_SHIFT) 202 + #define CDETCTRL1_CHGTYPMAN_MASK BIT(CDETCTRL1_CHGTYPMAN_SHIFT) 203 + #define CDETCTRL1_DCDEN_MASK BIT(CDETCTRL1_DCDEN_SHIFT) 204 + #define CDETCTRL1_DCD2SCT_MASK BIT(CDETCTRL1_DCD2SCT_SHIFT) 205 + #define CDETCTRL1_DCHKTM_MASK BIT(CDETCTRL1_DCHKTM_SHIFT) 206 + #define CDETCTRL1_DBEXIT_MASK BIT(CDETCTRL1_DBEXIT_SHIFT) 207 + #define CDETCTRL1_DBIDLE_MASK BIT(CDETCTRL1_DBIDLE_SHIFT) 208 + #define CDETCTRL1_CDPDET_MASK BIT(CDETCTRL1_CDPDET_SHIFT) 225 209 226 210 /* MAX14577 CHGCTRL1 register */ 227 211 #define CHGCTRL1_TCHW_SHIFT 4 ··· 229 213 230 214 /* MAX14577 CHGCTRL2 register */ 231 215 #define CHGCTRL2_MBCHOSTEN_SHIFT 6 232 - #define CHGCTRL2_MBCHOSTEN_MASK (0x1 << CHGCTRL2_MBCHOSTEN_SHIFT) 216 + #define CHGCTRL2_MBCHOSTEN_MASK BIT(CHGCTRL2_MBCHOSTEN_SHIFT) 233 217 #define CHGCTRL2_VCHGR_RC_SHIFT 7 234 - #define CHGCTRL2_VCHGR_RC_MASK (0x1 << CHGCTRL2_VCHGR_RC_SHIFT) 218 + #define CHGCTRL2_VCHGR_RC_MASK BIT(CHGCTRL2_VCHGR_RC_SHIFT) 235 219 236 220 /* MAX14577 CHGCTRL3 register */ 237 221 #define CHGCTRL3_MBCCVWRC_SHIFT 0 ··· 241 225 #define CHGCTRL4_MBCICHWRCH_SHIFT 0 242 226 #define CHGCTRL4_MBCICHWRCH_MASK (0xf << CHGCTRL4_MBCICHWRCH_SHIFT) 243 227 #define CHGCTRL4_MBCICHWRCL_SHIFT 4 244 - #define CHGCTRL4_MBCICHWRCL_MASK (0x1 << CHGCTRL4_MBCICHWRCL_SHIFT) 228 + #define CHGCTRL4_MBCICHWRCL_MASK BIT(CHGCTRL4_MBCICHWRCL_SHIFT) 245 229 246 230 /* MAX14577 CHGCTRL5 register */ 247 231 #define CHGCTRL5_EOCS_SHIFT 0 ··· 249 233 250 234 /* MAX14577 CHGCTRL6 register */ 251 235 #define CHGCTRL6_AUTOSTOP_SHIFT 5 252 - #define CHGCTRL6_AUTOSTOP_MASK (0x1 << CHGCTRL6_AUTOSTOP_SHIFT) 236 + #define CHGCTRL6_AUTOSTOP_MASK BIT(CHGCTRL6_AUTOSTOP_SHIFT) 253 237 254 238 /* MAX14577 CHGCTRL7 register */ 255 239 #define CHGCTRL7_OTPCGHCVS_SHIFT 0 ··· 261 245 #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000 262 246 #define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000 263 247 248 + /* MAX77836 regulator current limits (as in CHGCTRL4 register), uA */ 249 + #define MAX77836_REGULATOR_CURRENT_LIMIT_MIN 45000 250 + #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START 100000 251 + #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP 25000 252 + #define MAX77836_REGULATOR_CURRENT_LIMIT_MAX 475000 253 + 264 254 /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ 265 255 #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000 256 + 257 + /* MAX77836 regulator LDOx voltage, uV */ 258 + #define MAX77836_REGULATOR_LDO_VOLTAGE_MIN 800000 259 + #define MAX77836_REGULATOR_LDO_VOLTAGE_MAX 3950000 260 + #define MAX77836_REGULATOR_LDO_VOLTAGE_STEP 50000 261 + #define MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM 64 262 + 263 + /* Slave addr = 0x46: PMIC */ 264 + enum max77836_pmic_reg { 265 + MAX77836_PMIC_REG_PMIC_ID = 0x20, 266 + MAX77836_PMIC_REG_PMIC_REV = 0x21, 267 + MAX77836_PMIC_REG_INTSRC = 0x22, 268 + MAX77836_PMIC_REG_INTSRC_MASK = 0x23, 269 + MAX77836_PMIC_REG_TOPSYS_INT = 0x24, 270 + MAX77836_PMIC_REG_TOPSYS_INT_MASK = 0x26, 271 + MAX77836_PMIC_REG_TOPSYS_STAT = 0x28, 272 + MAX77836_PMIC_REG_MRSTB_CNTL = 0x2A, 273 + MAX77836_PMIC_REG_LSCNFG = 0x2B, 274 + 275 + MAX77836_LDO_REG_CNFG1_LDO1 = 0x51, 276 + MAX77836_LDO_REG_CNFG2_LDO1 = 0x52, 277 + MAX77836_LDO_REG_CNFG1_LDO2 = 0x53, 278 + MAX77836_LDO_REG_CNFG2_LDO2 = 0x54, 279 + MAX77836_LDO_REG_CNFG_LDO_BIAS = 0x55, 280 + 281 + MAX77836_COMP_REG_COMP1 = 0x60, 282 + 283 + MAX77836_PMIC_REG_END, 284 + }; 285 + 286 + #define MAX77836_INTSRC_MASK_TOP_INT_SHIFT 1 287 + #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT 3 288 + #define MAX77836_INTSRC_MASK_TOP_INT_MASK BIT(MAX77836_INTSRC_MASK_TOP_INT_SHIFT) 289 + #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK BIT(MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT) 290 + 291 + /* MAX77836 PMIC interrupts */ 292 + #define MAX77836_TOPSYS_INT_T120C_SHIFT 0 293 + #define MAX77836_TOPSYS_INT_T140C_SHIFT 1 294 + #define MAX77836_TOPSYS_INT_T120C_MASK BIT(MAX77836_TOPSYS_INT_T120C_SHIFT) 295 + #define MAX77836_TOPSYS_INT_T140C_MASK BIT(MAX77836_TOPSYS_INT_T140C_SHIFT) 296 + 297 + /* LDO1/LDO2 CONFIG1 register */ 298 + #define MAX77836_CNFG1_LDO_PWRMD_SHIFT 6 299 + #define MAX77836_CNFG1_LDO_TV_SHIFT 0 300 + #define MAX77836_CNFG1_LDO_PWRMD_MASK (0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT) 301 + #define MAX77836_CNFG1_LDO_TV_MASK (0x3f << MAX77836_CNFG1_LDO_TV_SHIFT) 302 + 303 + /* LDO1/LDO2 CONFIG2 register */ 304 + #define MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT 7 305 + #define MAX77836_CNFG2_LDO_ALPMEN_SHIFT 6 306 + #define MAX77836_CNFG2_LDO_COMP_SHIFT 4 307 + #define MAX77836_CNFG2_LDO_POK_SHIFT 3 308 + #define MAX77836_CNFG2_LDO_ADE_SHIFT 1 309 + #define MAX77836_CNFG2_LDO_SS_SHIFT 0 310 + #define MAX77836_CNFG2_LDO_OVCLMPEN_MASK BIT(MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT) 311 + #define MAX77836_CNFG2_LDO_ALPMEN_MASK BIT(MAX77836_CNFG2_LDO_ALPMEN_SHIFT) 312 + #define MAX77836_CNFG2_LDO_COMP_MASK (0x3 << MAX77836_CNFG2_LDO_COMP_SHIFT) 313 + #define MAX77836_CNFG2_LDO_POK_MASK BIT(MAX77836_CNFG2_LDO_POK_SHIFT) 314 + #define MAX77836_CNFG2_LDO_ADE_MASK BIT(MAX77836_CNFG2_LDO_ADE_SHIFT) 315 + #define MAX77836_CNFG2_LDO_SS_MASK BIT(MAX77836_CNFG2_LDO_SS_SHIFT) 316 + 317 + /* Slave addr = 0x6C: Fuel-Gauge/Battery */ 318 + enum max77836_fg_reg { 319 + MAX77836_FG_REG_VCELL_MSB = 0x02, 320 + MAX77836_FG_REG_VCELL_LSB = 0x03, 321 + MAX77836_FG_REG_SOC_MSB = 0x04, 322 + MAX77836_FG_REG_SOC_LSB = 0x05, 323 + MAX77836_FG_REG_MODE_H = 0x06, 324 + MAX77836_FG_REG_MODE_L = 0x07, 325 + MAX77836_FG_REG_VERSION_MSB = 0x08, 326 + MAX77836_FG_REG_VERSION_LSB = 0x09, 327 + MAX77836_FG_REG_HIBRT_H = 0x0A, 328 + MAX77836_FG_REG_HIBRT_L = 0x0B, 329 + MAX77836_FG_REG_CONFIG_H = 0x0C, 330 + MAX77836_FG_REG_CONFIG_L = 0x0D, 331 + MAX77836_FG_REG_VALRT_MIN = 0x14, 332 + MAX77836_FG_REG_VALRT_MAX = 0x15, 333 + MAX77836_FG_REG_CRATE_MSB = 0x16, 334 + MAX77836_FG_REG_CRATE_LSB = 0x17, 335 + MAX77836_FG_REG_VRESET = 0x18, 336 + MAX77836_FG_REG_FGID = 0x19, 337 + MAX77836_FG_REG_STATUS_H = 0x1A, 338 + MAX77836_FG_REG_STATUS_L = 0x1B, 339 + /* 340 + * TODO: TABLE registers 341 + * TODO: CMD register 342 + */ 343 + 344 + MAX77836_FG_REG_END, 345 + }; 266 346 267 347 enum max14577_irq { 268 348 /* INT1 */ 269 349 MAX14577_IRQ_INT1_ADC, 270 350 MAX14577_IRQ_INT1_ADCLOW, 271 351 MAX14577_IRQ_INT1_ADCERR, 352 + MAX77836_IRQ_INT1_ADC1K, 272 353 273 354 /* INT2 */ 274 355 MAX14577_IRQ_INT2_CHGTYP, ··· 373 260 MAX14577_IRQ_INT2_DCDTMR, 374 261 MAX14577_IRQ_INT2_DBCHG, 375 262 MAX14577_IRQ_INT2_VBVOLT, 263 + MAX77836_IRQ_INT2_VIDRM, 376 264 377 265 /* INT3 */ 378 266 MAX14577_IRQ_INT3_EOC, ··· 381 267 MAX14577_IRQ_INT3_OVP, 382 268 MAX14577_IRQ_INT3_MBCCHGERR, 383 269 270 + /* TOPSYS_INT, only MAX77836 */ 271 + MAX77836_IRQ_TOPSYS_T140C, 272 + MAX77836_IRQ_TOPSYS_T120C, 273 + 384 274 MAX14577_IRQ_NUM, 385 275 }; 386 276 387 277 struct max14577 { 388 278 struct device *dev; 389 279 struct i2c_client *i2c; /* Slave addr = 0x4A */ 280 + struct i2c_client *i2c_pmic; /* Slave addr = 0x46 */ 281 + enum maxim_device_type dev_type; 390 282 391 - struct regmap *regmap; 283 + struct regmap *regmap; /* For MUIC and Charger */ 284 + struct regmap *regmap_pmic; 392 285 393 - struct regmap_irq_chip_data *irq_data; 286 + struct regmap_irq_chip_data *irq_data; /* For MUIC and Charger */ 287 + struct regmap_irq_chip_data *irq_data_pmic; 394 288 int irq; 395 - 396 - /* Device ID */ 397 - u8 vendor_id; /* Vendor Identification */ 398 - u8 device_id; /* Chip Version */ 399 289 }; 400 290 401 291 /* MAX14577 shared regmap API function */
+16 -3
include/linux/mfd/max14577.h
··· 1 1 /* 2 - * max14577.h - Driver for the Maxim 14577 2 + * max14577.h - Driver for the Maxim 14577/77836 3 3 * 4 - * Copyright (C) 2013 Samsung Electrnoics 4 + * Copyright (C) 2014 Samsung Electrnoics 5 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 7 7 * ··· 20 20 * MAX14577 has MUIC, Charger devices. 21 21 * The devices share the same I2C bus and interrupt line 22 22 * included in this mfd driver. 23 + * 24 + * MAX77836 has additional PMIC and Fuel-Gauge on different I2C slave 25 + * addresses. 23 26 */ 24 27 25 28 #ifndef __MAX14577_H__ ··· 35 32 MAX14577_SAFEOUT = 0, 36 33 MAX14577_CHARGER, 37 34 38 - MAX14577_REG_MAX, 35 + MAX14577_REGULATOR_NUM, 36 + }; 37 + 38 + /* MAX77836 regulator IDs */ 39 + enum max77836_regulators { 40 + MAX77836_SAFEOUT = 0, 41 + MAX77836_CHARGER, 42 + MAX77836_LDO1, 43 + MAX77836_LDO2, 44 + 45 + MAX77836_REGULATOR_NUM, 39 46 }; 40 47 41 48 struct max14577_regulator_platform_data {
+5 -14
include/linux/mfd/stmpe.h
··· 11 11 #include <linux/mutex.h> 12 12 13 13 struct device; 14 + struct regulator; 14 15 15 16 enum stmpe_block { 16 17 STMPE_BLOCK_GPIO = 1 << 0, ··· 63 62 64 63 /** 65 64 * struct stmpe - STMPE MFD structure 65 + * @vcc: optional VCC regulator 66 + * @vio: optional VIO regulator 66 67 * @lock: lock protecting I/O operations 67 68 * @irq_lock: IRQ bus lock 68 69 * @dev: device, mostly for dev_dbg() ··· 76 73 * @regs: list of addresses of registers which are at different addresses on 77 74 * different variants. Indexed by one of STMPE_IDX_*. 78 75 * @irq: irq number for stmpe 79 - * @irq_base: starting IRQ number for internal IRQs 80 76 * @num_gpios: number of gpios, differs for variants 81 77 * @ier: cache of IER registers for bus_lock 82 78 * @oldier: cache of IER registers for bus_lock 83 79 * @pdata: platform data 84 80 */ 85 81 struct stmpe { 82 + struct regulator *vcc; 83 + struct regulator *vio; 86 84 struct mutex lock; 87 85 struct mutex irq_lock; 88 86 struct device *dev; ··· 95 91 const u8 *regs; 96 92 97 93 int irq; 98 - int irq_base; 99 94 int num_gpios; 100 95 u8 ier[2]; 101 96 u8 oldier[2]; ··· 135 132 136 133 /** 137 134 * struct stmpe_gpio_platform_data - STMPE GPIO platform data 138 - * @gpio_base: first gpio number assigned. A maximum of 139 - * %STMPE_NR_GPIOS GPIOs will be allocated. 140 135 * @norequest_mask: bitmask specifying which GPIOs should _not_ be 141 136 * requestable due to different usage (e.g. touch, keypad) 142 137 * STMPE_GPIO_NOREQ_* macros can be used here. ··· 142 141 * @remove: board specific remove callback 143 142 */ 144 143 struct stmpe_gpio_platform_data { 145 - int gpio_base; 146 144 unsigned norequest_mask; 147 145 void (*setup)(struct stmpe *stmpe, unsigned gpio_base); 148 146 void (*remove)(struct stmpe *stmpe, unsigned gpio_base); ··· 195 195 * @irq_trigger: IRQ trigger to use for the interrupt to the host 196 196 * @autosleep: bool to enable/disable stmpe autosleep 197 197 * @autosleep_timeout: inactivity timeout in milliseconds for autosleep 198 - * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or 199 - * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used. 200 198 * @irq_over_gpio: true if gpio is used to get irq 201 199 * @irq_gpio: gpio number over which irq will be requested (significant only if 202 200 * irq_over_gpio is true) ··· 205 207 struct stmpe_platform_data { 206 208 int id; 207 209 unsigned int blocks; 208 - int irq_base; 209 210 unsigned int irq_trigger; 210 211 bool autosleep; 211 212 bool irq_over_gpio; ··· 215 218 struct stmpe_keypad_platform_data *keypad; 216 219 struct stmpe_ts_platform_data *ts; 217 220 }; 218 - 219 - #define STMPE_NR_INTERNAL_IRQS 9 220 - #define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x)) 221 - 222 - #define STMPE_NR_GPIOS 24 223 - #define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS) 224 221 225 222 #endif
+14
include/linux/mfd/tps65090.h
··· 64 64 TPS65090_REGULATOR_MAX, 65 65 }; 66 66 67 + /* Register addresses */ 68 + #define TPS65090_REG_INTR_STS 0x00 69 + #define TPS65090_REG_INTR_STS2 0x01 70 + #define TPS65090_REG_INTR_MASK 0x02 71 + #define TPS65090_REG_INTR_MASK2 0x03 72 + #define TPS65090_REG_CG_CTRL0 0x04 73 + #define TPS65090_REG_CG_CTRL1 0x05 74 + #define TPS65090_REG_CG_CTRL2 0x06 75 + #define TPS65090_REG_CG_CTRL3 0x07 76 + #define TPS65090_REG_CG_CTRL4 0x08 77 + #define TPS65090_REG_CG_CTRL5 0x09 78 + #define TPS65090_REG_CG_STATUS1 0x0a 79 + #define TPS65090_REG_CG_STATUS2 0x0b 80 + 67 81 struct tps65090 { 68 82 struct device *dev; 69 83 struct regmap *rmap;
+2
include/linux/mfd/tps6586x.h
··· 17 17 #define TPS658621A 0x15 18 18 #define TPS658621CD 0x2c 19 19 #define TPS658623 0x1b 20 + #define TPS658640 0x01 21 + #define TPS658640v2 0x02 20 22 #define TPS658643 0x03 21 23 22 24 enum {
+13 -1
sound/soc/codecs/mc13783.c
··· 22 22 */ 23 23 #include <linux/module.h> 24 24 #include <linux/device.h> 25 + #include <linux/of.h> 25 26 #include <linux/mfd/mc13xxx.h> 26 27 #include <linux/slab.h> 27 28 #include <sound/core.h> ··· 751 750 { 752 751 struct mc13783_priv *priv; 753 752 struct mc13xxx_codec_platform_data *pdata = pdev->dev.platform_data; 753 + struct device_node *np; 754 754 int ret; 755 755 756 756 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); ··· 762 760 priv->adc_ssi_port = pdata->adc_ssi_port; 763 761 priv->dac_ssi_port = pdata->dac_ssi_port; 764 762 } else { 765 - return -ENOSYS; 763 + np = of_get_child_by_name(pdev->dev.parent->of_node, "codec"); 764 + if (!np) 765 + return -ENOSYS; 766 + 767 + ret = of_property_read_u32(np, "adc-port", &priv->adc_ssi_port); 768 + if (ret) 769 + return ret; 770 + 771 + ret = of_property_read_u32(np, "dac-port", &priv->dac_ssi_port); 772 + if (ret) 773 + return ret; 766 774 } 767 775 768 776 dev_set_drvdata(&pdev->dev, priv);