Skip to content

Commit 72f2e2c

Browse files
kishore kadiyalaSamuel Ortiz
authored andcommitted
mfd: Adding twl6030 mmc card detect support for MMC1
Adding card detect callback function and card detect configuration function for MMC1 Controller on OMAP4. Card detect configuration function does initial configuration of the MMC Control & PullUp-PullDown registers of Phoenix. For MMC1 Controller, card detect interrupt source is twl6030 which is non-gpio. The card detect call back function provides card present/absent status by reading MMC Control register present on twl6030. Since OMAP4 doesn't use any GPIO line as used in OMAP3 for card detect, the suspend/resume initialization which was done in omap_hsmmc_gpio_init previously is moved to the probe thus making it generic for both OMAP3 & OMAP4. Cc: Tony Lindgren <tony@atomide.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Madhusudhan Chikkature <madhu.cr@ti.com> Cc: Adrian Hunter <adrian.hunter@nokia.com> Signed-off-by: Kishore Kadiyala <kishore.kadiyala@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 8e00593 commit 72f2e2c

4 files changed

Lines changed: 112 additions & 3 deletions

File tree

‎arch/arm/mach-omap2/board-4430sdp.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,14 @@ static int omap4_twl6030_hsmmc_late_init(struct device *dev)
269269
struct omap_mmc_platform_data *pdata = dev->platform_data;
270270

271271
/* Setting MMC1 Card detect Irq */
272-
if (pdev->id == 0)
272+
if (pdev->id == 0) {
273+
ret = twl6030_mmc_card_detect_config();
274+
if (ret)
275+
pr_err("Failed configuring MMC1 card detect\n");
273276
pdata->slots[0].card_detect_irq = TWL6030_IRQ_BASE +
274277
MMCDETECT_INTR_OFFSET;
278+
pdata->slots[0].card_detect = twl6030_mmc_card_detect;
279+
}
275280
return ret;
276281
}
277282

‎drivers/mfd/twl6030-irq.c‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/irq.h>
3737
#include <linux/kthread.h>
3838
#include <linux/i2c/twl.h>
39+
#include <linux/platform_device.h>
3940

4041
/*
4142
* TWL6030 (unlike its predecessors, which had two level interrupt handling)
@@ -223,6 +224,78 @@ int twl6030_interrupt_mask(u8 bit_mask, u8 offset)
223224
}
224225
EXPORT_SYMBOL(twl6030_interrupt_mask);
225226

227+
int twl6030_mmc_card_detect_config(void)
228+
{
229+
int ret;
230+
u8 reg_val = 0;
231+
232+
/* Unmasking the Card detect Interrupt line for MMC1 from Phoenix */
233+
twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK,
234+
REG_INT_MSK_LINE_B);
235+
twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK,
236+
REG_INT_MSK_STS_B);
237+
/*
238+
* Intially Configuring MMC_CTRL for receving interrupts &
239+
* Card status on TWL6030 for MMC1
240+
*/
241+
ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &reg_val, TWL6030_MMCCTRL);
242+
if (ret < 0) {
243+
pr_err("twl6030: Failed to read MMCCTRL, error %d\n", ret);
244+
return ret;
245+
}
246+
reg_val &= ~VMMC_AUTO_OFF;
247+
reg_val |= SW_FC;
248+
ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val, TWL6030_MMCCTRL);
249+
if (ret < 0) {
250+
pr_err("twl6030: Failed to write MMCCTRL, error %d\n", ret);
251+
return ret;
252+
}
253+
254+
/* Configuring PullUp-PullDown register */
255+
ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &reg_val,
256+
TWL6030_CFG_INPUT_PUPD3);
257+
if (ret < 0) {
258+
pr_err("twl6030: Failed to read CFG_INPUT_PUPD3, error %d\n",
259+
ret);
260+
return ret;
261+
}
262+
reg_val &= ~(MMC_PU | MMC_PD);
263+
ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val,
264+
TWL6030_CFG_INPUT_PUPD3);
265+
if (ret < 0) {
266+
pr_err("twl6030: Failed to write CFG_INPUT_PUPD3, error %d\n",
267+
ret);
268+
return ret;
269+
}
270+
return 0;
271+
}
272+
EXPORT_SYMBOL(twl6030_mmc_card_detect_config);
273+
274+
int twl6030_mmc_card_detect(struct device *dev, int slot)
275+
{
276+
int ret = -EIO;
277+
u8 read_reg = 0;
278+
struct platform_device *pdev = to_platform_device(dev);
279+
280+
if (pdev->id) {
281+
/* TWL6030 provide's Card detect support for
282+
* only MMC1 controller.
283+
*/
284+
pr_err("Unkown MMC controller %d in %s\n", pdev->id, __func__);
285+
return ret;
286+
}
287+
/*
288+
* BIT0 of MMC_CTRL on TWL6030 provides card status for MMC1
289+
* 0 - Card not present ,1 - Card present
290+
*/
291+
ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &read_reg,
292+
TWL6030_MMCCTRL);
293+
if (ret >= 0)
294+
ret = read_reg & STS_MMC;
295+
return ret;
296+
}
297+
EXPORT_SYMBOL(twl6030_mmc_card_detect);
298+
226299
int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
227300
{
228301

‎drivers/mmc/host/omap_hsmmc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata)
483483
int ret;
484484

485485
if (gpio_is_valid(pdata->slots[0].switch_pin)) {
486-
pdata->suspend = omap_hsmmc_suspend_cdirq;
487-
pdata->resume = omap_hsmmc_resume_cdirq;
488486
if (pdata->slots[0].cover)
489487
pdata->slots[0].get_cover_state =
490488
omap_hsmmc_get_cover_state;
@@ -2218,6 +2216,8 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
22182216
"Unable to grab MMC CD IRQ\n");
22192217
goto err_irq_cd;
22202218
}
2219+
pdata->suspend = omap_hsmmc_suspend_cdirq;
2220+
pdata->resume = omap_hsmmc_resume_cdirq;
22212221
}
22222222

22232223
omap_hsmmc_disable_irq(host);

‎include/linux/i2c/twl.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@
141141
#define TWL6030_CHARGER_CTRL_INT_MASK 0x10
142142
#define TWL6030_CHARGER_FAULT_INT_MASK 0x60
143143

144+
#define TWL6030_MMCCTRL 0xEE
145+
#define VMMC_AUTO_OFF (0x1 << 3)
146+
#define SW_FC (0x1 << 2)
147+
#define STS_MMC 0x1
148+
149+
#define TWL6030_CFG_INPUT_PUPD3 0xF2
150+
#define MMC_PU (0x1 << 3)
151+
#define MMC_PD (0x1 << 2)
152+
153+
144154

145155
#define TWL4030_CLASS_ID 0x4030
146156
#define TWL6030_CLASS_ID 0x6030
@@ -173,6 +183,27 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes);
173183
int twl6030_interrupt_unmask(u8 bit_mask, u8 offset);
174184
int twl6030_interrupt_mask(u8 bit_mask, u8 offset);
175185

186+
/* Card detect Configuration for MMC1 Controller on OMAP4 */
187+
#ifdef CONFIG_TWL4030_CORE
188+
int twl6030_mmc_card_detect_config(void);
189+
#else
190+
static inline int twl6030_mmc_card_detect_config(void)
191+
{
192+
pr_debug("twl6030_mmc_card_detect_config not supported\n");
193+
return 0;
194+
}
195+
#endif
196+
197+
/* MMC1 Controller on OMAP4 uses Phoenix irq for Card detect */
198+
#ifdef CONFIG_TWL4030_CORE
199+
int twl6030_mmc_card_detect(struct device *dev, int slot);
200+
#else
201+
static inline int twl6030_mmc_card_detect(struct device *dev, int slot)
202+
{
203+
pr_debug("Call back twl6030_mmc_card_detect not supported\n");
204+
return -EIO;
205+
}
206+
#endif
176207
/*----------------------------------------------------------------------*/
177208

178209
/*

0 commit comments

Comments
 (0)