root/arch/arm/mach-omap2/hsmmc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. omap_hsmmc_pdata_init
  2. omap_hsmmc_late_init
  3. omap_hsmmc_init_one
  4. omap_hsmmc_init

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * linux/arch/arm/mach-omap2/hsmmc.c
   4  *
   5  * Copyright (C) 2007-2008 Texas Instruments
   6  * Copyright (C) 2008 Nokia Corporation
   7  * Author: Texas Instruments
   8  */
   9 #include <linux/kernel.h>
  10 #include <linux/slab.h>
  11 #include <linux/string.h>
  12 #include <linux/delay.h>
  13 #include <linux/mmc/host.h>
  14 #include <linux/platform_data/hsmmc-omap.h>
  15 
  16 #include "soc.h"
  17 #include "omap_device.h"
  18 
  19 #include "hsmmc.h"
  20 #include "control.h"
  21 
  22 #if IS_ENABLED(CONFIG_MMC_OMAP_HS)
  23 
  24 static u16 control_pbias_offset;
  25 static u16 control_devconf1_offset;
  26 
  27 #define HSMMC_NAME_LEN  9
  28 
  29 static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
  30                                         struct omap_hsmmc_platform_data *mmc)
  31 {
  32         char *hc_name;
  33 
  34         hc_name = kzalloc(HSMMC_NAME_LEN + 1, GFP_KERNEL);
  35         if (!hc_name)
  36                 return -ENOMEM;
  37 
  38         snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
  39         mmc->name = hc_name;
  40         mmc->caps = c->caps;
  41         mmc->reg_offset = 0;
  42 
  43         return 0;
  44 }
  45 
  46 static int omap_hsmmc_done;
  47 
  48 void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
  49 {
  50         struct platform_device *pdev;
  51         int res;
  52 
  53         if (omap_hsmmc_done)
  54                 return;
  55 
  56         omap_hsmmc_done = 1;
  57 
  58         for (; c->mmc; c++) {
  59                 pdev = c->pdev;
  60                 if (!pdev)
  61                         continue;
  62                 res = omap_device_register(pdev);
  63                 if (res)
  64                         pr_err("Could not late init MMC\n");
  65         }
  66 }
  67 
  68 #define MAX_OMAP_MMC_HWMOD_NAME_LEN             16
  69 
  70 static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
  71                                         int ctrl_nr)
  72 {
  73         struct omap_hwmod *oh;
  74         struct omap_hwmod *ohs[1];
  75         struct omap_device *od;
  76         struct platform_device *pdev;
  77         char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
  78         struct omap_hsmmc_platform_data *mmc_data;
  79         struct omap_hsmmc_dev_attr *mmc_dev_attr;
  80         char *name;
  81         int res;
  82 
  83         mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
  84         if (!mmc_data)
  85                 return;
  86 
  87         res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
  88         if (res < 0)
  89                 goto free_mmc;
  90 
  91         name = "omap_hsmmc";
  92         res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
  93                      "mmc%d", ctrl_nr);
  94         WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
  95              "String buffer overflow in MMC%d device setup\n", ctrl_nr);
  96 
  97         oh = omap_hwmod_lookup(oh_name);
  98         if (!oh) {
  99                 pr_err("Could not look up %s\n", oh_name);
 100                 goto free_name;
 101         }
 102         ohs[0] = oh;
 103         if (oh->dev_attr != NULL) {
 104                 mmc_dev_attr = oh->dev_attr;
 105                 mmc_data->controller_flags = mmc_dev_attr->flags;
 106         }
 107 
 108         pdev = platform_device_alloc(name, ctrl_nr - 1);
 109         if (!pdev) {
 110                 pr_err("Could not allocate pdev for %s\n", name);
 111                 goto free_name;
 112         }
 113         dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
 114 
 115         od = omap_device_alloc(pdev, ohs, 1);
 116         if (IS_ERR(od)) {
 117                 pr_err("Could not allocate od for %s\n", name);
 118                 goto put_pdev;
 119         }
 120 
 121         res = platform_device_add_data(pdev, mmc_data,
 122                               sizeof(struct omap_hsmmc_platform_data));
 123         if (res) {
 124                 pr_err("Could not add pdata for %s\n", name);
 125                 goto put_pdev;
 126         }
 127 
 128         hsmmcinfo->pdev = pdev;
 129 
 130         res = omap_device_register(pdev);
 131         if (res) {
 132                 pr_err("Could not register od for %s\n", name);
 133                 goto free_od;
 134         }
 135 
 136         goto free_mmc;
 137 
 138 free_od:
 139         omap_device_delete(od);
 140 
 141 put_pdev:
 142         platform_device_put(pdev);
 143 
 144 free_name:
 145         kfree(mmc_data->name);
 146 
 147 free_mmc:
 148         kfree(mmc_data);
 149 }
 150 
 151 void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
 152 {
 153         if (omap_hsmmc_done)
 154                 return;
 155 
 156         omap_hsmmc_done = 1;
 157 
 158         if (cpu_is_omap2430()) {
 159                 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
 160                 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
 161         } else {
 162                 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
 163                 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
 164         }
 165 
 166         for (; controllers->mmc; controllers++)
 167                 omap_hsmmc_init_one(controllers, controllers->mmc);
 168 
 169 }
 170 
 171 #endif

/* [<][>][^][v][top][bottom][index][help] */