Blame view

drivers/mmc/hi6220_dw_mmc.c 2.7 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
2
3
4
  /*
   * (C) Copyright 2015 Linaro
   * peter.griffin <peter.griffin@linaro.org>
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
5
6
7
   */
  
  #include <common.h>
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
8
  #include <dm.h>
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
9
  #include <dwmmc.h>
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
10
11
  #include <errno.h>
  #include <fdtdec.h>
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
12
  #include <malloc.h>
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
13

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
14
  DECLARE_GLOBAL_DATA_PTR;
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
15

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
16
17
18
19
  struct hi6220_dwmmc_plat {
  	struct mmc_config cfg;
  	struct mmc mmc;
  };
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
20

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
21
22
23
  struct hi6220_dwmmc_priv_data {
  	struct dwmci_host host;
  };
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
24

122537e1f   Manivannan Sadhasivam   mmc: Add support ...
25
26
27
28
  struct hisi_mmc_data {
  	unsigned int clock;
  	bool use_fifo;
  };
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
29
  static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
30
  {
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
31
32
  	struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
  	struct dwmci_host *host = &priv->host;
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
33

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
34
35
36
37
38
39
40
41
42
43
44
45
  	host->name = dev->name;
  	host->ioaddr = (void *)devfdt_get_addr(dev);
  	host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  					"bus-width", 4);
  
  	/* use non-removable property for differentiating SD card and eMMC */
  	if (dev_read_bool(dev, "non-removable"))
  		host->dev_index = 0;
  	else
  		host->dev_index = 1;
  
  	host->priv = priv;
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
46

447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
47
48
  	return 0;
  }
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
49
  static int hi6220_dwmmc_probe(struct udevice *dev)
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
50
  {
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
51
52
53
54
  	struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
  	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  	struct hi6220_dwmmc_priv_data *priv = dev_get_priv(dev);
  	struct dwmci_host *host = &priv->host;
122537e1f   Manivannan Sadhasivam   mmc: Add support ...
55
56
57
  	struct hisi_mmc_data *mmc_data;
  
  	mmc_data = (struct hisi_mmc_data *)dev_get_driver_data(dev);
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
58

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
59
  	/* Use default bus speed due to absence of clk driver */
122537e1f   Manivannan Sadhasivam   mmc: Add support ...
60
  	host->bus_hz = mmc_data->clock;
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
61

6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
62
63
  	dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, 400000);
  	host->mmc = &plat->mmc;
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
64

122537e1f   Manivannan Sadhasivam   mmc: Add support ...
65
  	host->fifo_mode = mmc_data->use_fifo;
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
66
67
68
69
70
  	host->mmc->priv = &priv->host;
  	upriv->mmc = host->mmc;
  	host->mmc->dev = dev;
  
  	return dwmci_probe(dev);
447da58b5   Peter Griffin   mmc: hi6220_dw_mm...
71
  }
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
72
73
74
75
76
77
78
79
80
81
82
83
  
  static int hi6220_dwmmc_bind(struct udevice *dev)
  {
  	struct hi6220_dwmmc_plat *plat = dev_get_platdata(dev);
  	int ret;
  
  	ret = dwmci_bind(dev, &plat->mmc, &plat->cfg);
  	if (ret)
  		return ret;
  
  	return 0;
  }
122537e1f   Manivannan Sadhasivam   mmc: Add support ...
84
85
86
87
88
89
90
91
92
  static const struct hisi_mmc_data hi3660_mmc_data = {
  	.clock = 3200000,
  	.use_fifo = true,
  };
  
  static const struct hisi_mmc_data hi6220_mmc_data = {
  	.clock = 50000000,
  	.use_fifo = false,
  };
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
93
  static const struct udevice_id hi6220_dwmmc_ids[] = {
122537e1f   Manivannan Sadhasivam   mmc: Add support ...
94
95
96
97
98
99
  	{ .compatible = "hisilicon,hi6220-dw-mshc",
  	  .data = (ulong)&hi6220_mmc_data },
  	{ .compatible = "hisilicon,hi3798cv200-dw-mshc",
  	  .data = (ulong)&hi6220_mmc_data },
  	{ .compatible = "hisilicon,hi3660-dw-mshc",
  	  .data = (ulong)&hi3660_mmc_data },
6240e64f9   Manivannan Sadhasivam   mmc: Convert HI62...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  	{ }
  };
  
  U_BOOT_DRIVER(hi6220_dwmmc_drv) = {
  	.name = "hi6220_dwmmc",
  	.id = UCLASS_MMC,
  	.of_match = hi6220_dwmmc_ids,
  	.ofdata_to_platdata = hi6220_dwmmc_ofdata_to_platdata,
  	.ops = &dm_dwmci_ops,
  	.bind = hi6220_dwmmc_bind,
  	.probe = hi6220_dwmmc_probe,
  	.priv_auto_alloc_size = sizeof(struct hi6220_dwmmc_priv_data),
  	.platdata_auto_alloc_size = sizeof(struct hi6220_dwmmc_plat),
  };