1 From 0e70d711fe8c81a98b77b35b56728e29a669a08b Mon Sep 17 00:00:00 2001
2 From: Holger Freyther <zecke@openmoko.org>
3 Date: Mon, 4 Aug 2008 08:34:39 +0100
4 Subject: [PATCH] 0003-a6k-sdio-Use-pnp_alloc_dev-to-properly-initialize.patch
5 Signed-Off-By: Holger Freyther <zecke@openmoko.org>
8 drivers/sdio/function/wlan/ar6000/hif/hif.c | 2 +-
9 drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.c | 6 +-
10 drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.h | 4 +-
11 drivers/sdio/stack/busdriver/sdio_bus_os.c | 78 ++++++++++++++-------------
12 include/linux/sdio/sdio_busdriver.h | 2 +-
13 include/linux/sdio/sdio_hcd_defs.h | 2 +-
14 6 files changed, 48 insertions(+), 46 deletions(-)
16 diff --git a/drivers/sdio/function/wlan/ar6000/hif/hif.c b/drivers/sdio/function/wlan/ar6000/hif/hif.c
17 index 3d6d792..5171157 100644
18 --- a/drivers/sdio/function/wlan/ar6000/hif/hif.c
19 +++ b/drivers/sdio/function/wlan/ar6000/hif/hif.c
20 @@ -782,7 +782,7 @@ delHifDevice(SDDEVICE *handle)
22 HIFGetOSDevice(HIF_DEVICE *device)
24 - return &device->handle->Device.dev;
25 + return &device->handle->Device->dev;
28 static void ResetAllCards(void)
29 diff --git a/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.c b/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.c
30 index edb8523..09d81ee 100644
31 --- a/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.c
32 +++ b/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.c
33 @@ -1296,7 +1296,6 @@ struct s3c24xx_hcd_context hcd_context = {
34 .hcd.pContext = &hcd_context,
35 .hcd.pRequest = s3c24xx_hcd_request,
36 .hcd.pConfigure = s3c24xx_hcd_config,
37 - .device.pnp_device.name = "sdio_s3c24xx_hcd",
38 .device.pnp_driver.name = "sdio_s3c24xx_hcd",
39 .device.pnp_driver.probe = s3c24xx_hcd_pnp_probe,
40 .device.pnp_driver.remove = s3c24xx_hcd_pnp_remove,
41 @@ -1348,7 +1347,7 @@ static int s3c24xx_hcd_probe(struct platform_device * pdev)
43 status = SDIO_BusAddOSDevice(&hcd_context.device.dma,
44 &hcd_context.device.pnp_driver,
45 - &hcd_context.device.pnp_device);
46 + &hcd_context.device.pnp_device, "sdio_s3c24xx_hcd");
50 @@ -1360,7 +1359,8 @@ static int s3c24xx_hcd_probe(struct platform_device * pdev)
52 static int s3c24xx_hcd_remove(struct platform_device * pdev) {
53 printk("S3C2440 SDIO host controller unloaded\n");
54 - SDIO_BusRemoveOSDevice(&hcd_context.device.pnp_driver, &hcd_context.device.pnp_device);
55 + SDIO_BusRemoveOSDevice(&hcd_context.device.pnp_driver, hcd_context.device.pnp_device);
56 + kfree(hcd_context.device.pnp_device);
60 diff --git a/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.h b/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.h
61 index 47fdd33..f8b0912 100644
62 --- a/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.h
63 +++ b/drivers/sdio/hcd/s3c24xx/s3c24xx_hcd.h
65 #define S3C24XX_HCD_DATA_WRITE 5
67 struct s3c24xx_hcd_device {
68 - OS_PNPDEVICE pnp_device; /* the OS device for this HCD */
69 - OS_PNPDRIVER pnp_driver; /* the OS driver for this HCD */
70 + OS_PNPDEVICE *pnp_device; /* the OS device for this HCD */
71 + OS_PNPDRIVER pnp_driver; /* the OS driver for this HCD */
72 SDDMA_DESCRIPTION dma;
74 unsigned long max_clock_rate;
75 diff --git a/drivers/sdio/stack/busdriver/sdio_bus_os.c b/drivers/sdio/stack/busdriver/sdio_bus_os.c
76 index 2650d93..c6f68e6 100644
77 --- a/drivers/sdio/stack/busdriver/sdio_bus_os.c
78 +++ b/drivers/sdio/stack/busdriver/sdio_bus_os.c
79 @@ -415,8 +415,8 @@ struct pnp_protocol sdio_protocol = {
81 static int driver_probe(struct pnp_dev* pOSDevice, const struct pnp_device_id *pId)
83 - PSDDEVICE pDevice = SDDEVICE_FROM_OSDEVICE(pOSDevice);
84 - PSDFUNCTION pFunction = pDevice->Device.dev.driver_data;
85 + PSDDEVICE pDevice = SDDEVICE_FROM_OSDEVICE(&pOSDevice);
86 + PSDFUNCTION pFunction = pDevice->Device->dev.driver_data;
88 if (pFunction == NULL) {
90 @@ -496,34 +496,32 @@ static int UnregisterDriver(PSDFUNCTION pFunction)
92 SDIO_STATUS OS_InitializeDevice(PSDDEVICE pDevice, PSDFUNCTION pFunction)
97 - memset(&pDevice->Device, 0, sizeof(pDevice->Device));
98 - pDevice->Device.dev.driver_data = (PVOID)pFunction;
99 + /* set the id as slot number/function number */
100 + snprintf(id_name, sizeof(id_name) - 1, "SD_%02X%02X",
101 + pDevice->pHcd->SlotNumber, (UINT)SDDEVICE_GET_SDIO_FUNCNO(pDevice));
103 + pDevice->Device = pnp_alloc_dev(&sdio_protocol, pDevice->pHcd->SlotNumber + 1, id_name);
104 + pDevice->Device->dev.driver_data = (PVOID)pFunction;
105 //?? pDevice->Device.data = (PVOID)pFunction;
106 //?? pDevice->Device.dev.driver = &pFunction->Driver.driver;
107 //?? pDevice->Device.driver = &pFunction->Driver;
108 //?? pDevice->Device.dev.release = release;
109 /* get a unique device number, must be done with locks held */
110 spin_lock(&InUseDevicesLock);
111 - pDevice->Device.number = FirstClearBit(&InUseDevices);
112 - SetBit(&InUseDevices, pDevice->Device.number);
113 + pDevice->Device->number = FirstClearBit(&InUseDevices);
114 + SetBit(&InUseDevices, pDevice->Device->number);
115 spin_unlock(&InUseDevicesLock);
116 - pDevice->Device.capabilities = PNP_REMOVABLE | PNP_DISABLE;
117 - pDevice->Device.protocol = &sdio_protocol;
118 - pDevice->Device.active = 1;
119 + pDevice->Device->capabilities = PNP_REMOVABLE | PNP_DISABLE;
120 + pDevice->Device->active = 1;
122 - /* set the id as slot number/function number */
123 - snprintf(id_name, sizeof(id_name) - 1, "SD_%02X%02X",
124 - pDevice->pHcd->SlotNumber, (UINT)SDDEVICE_GET_SDIO_FUNCNO(pDevice));
125 DBG_PRINT(SDDBG_TRACE, ("SDIO BusDriver - OS_InitializeDevice adding id: %s\n",
127 - pnp_add_id(&pDevice->Device, id_name);
129 - /* deal with DMA settings */
130 + /* deal with DMA settings */
131 if (pDevice->pHcd->pDmaDescription != NULL) {
132 - pDevice->Device.dev.dma_mask = &pDevice->pHcd->pDmaDescription->Mask;
133 - pDevice->Device.dev.coherent_dma_mask = pDevice->pHcd->pDmaDescription->Mask;
134 + pDevice->Device->dev.dma_mask = &pDevice->pHcd->pDmaDescription->Mask;
135 + pDevice->Device->dev.coherent_dma_mask = pDevice->pHcd->pDmaDescription->Mask;
138 return SDIO_STATUS_SUCCESS;
139 @@ -537,13 +535,13 @@ SDIO_STATUS OS_AddDevice(PSDDEVICE pDevice, PSDFUNCTION pFunction)
141 DBG_PRINT(SDDBG_TRACE, ("SDIO BusDriver - OS_AddDevice adding function: %s\n",
143 - error = pnp_add_device(&pDevice->Device);
144 + error = pnp_add_device(pDevice->Device);
146 DBG_PRINT(SDDBG_ERROR, ("SDIO BusDriver - OS_AddDevice failed pnp_add_device: %d\n",
149 /* replace the buggy pnp's release */
150 - pDevice->Device.dev.release = release;
151 + pDevice->Device->dev.release = release;
153 return OSErrorToSDIOError(error);
155 @@ -554,15 +552,17 @@ SDIO_STATUS OS_AddDevice(PSDDEVICE pDevice, PSDFUNCTION pFunction)
156 void OS_RemoveDevice(PSDDEVICE pDevice)
158 DBG_PRINT(SDDBG_TRACE, ("SDIO BusDriver - OS_RemoveDevice \n"));
159 - pnp_remove_card_device(&pDevice->Device);
160 + pnp_remove_card_device(pDevice->Device);
161 spin_lock(&InUseDevicesLock);
162 - ClearBit(&InUseDevices, pDevice->Device.number);
163 + ClearBit(&InUseDevices, pDevice->Device->number);
164 spin_unlock(&InUseDevicesLock);
166 - if (pDevice->Device.id != NULL) {
167 - KernelFree(pDevice->Device.id);
168 - pDevice->Device.id = NULL;
169 + if (pDevice->Device->id != NULL) {
170 + KernelFree(pDevice->Device->id);
171 + pDevice->Device->id = NULL;
174 + KernelFree(pDevice->Device);
177 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178 @@ -612,20 +612,13 @@ void OS_RemoveDevice(PSDDEVICE pDevice)
179 @see also: SDIO_BusRemoveOSDevice
181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
182 -SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver, POS_PNPDEVICE pDevice)
183 +SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver, POS_PNPDEVICE *outDevice, const char* name)
186 struct pnp_device_id *pFdid;
187 static int slotNumber = 0; /* we just use an increasing count for the slots number */
189 + struct pnp_dev* pDevice;
191 - if (pDma != NULL) {
192 - pDevice->dev.dma_mask = &pDma->Mask;
193 - pDevice->dev.coherent_dma_mask = pDma->Mask;
195 - DBG_PRINT(SDDBG_ERROR,
196 - ("SDIO BusDriver - SDIO_GetBusOSDevice, registering driver: %s DMAmask: 0x%x\n",
197 - pDriver->name, (UINT)*pDevice->dev.dma_mask));
198 pFdid = KernelAlloc(sizeof(struct pnp_device_id)*2);
199 /* set the id as slot number/function number */
200 snprintf(pFdid[0].id, sizeof(pFdid[0].id), "SD_%02X08",
201 @@ -644,14 +637,22 @@ SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver,
202 return OSErrorToSDIOError(err);
205 + pDevice = pnp_alloc_dev(&sdio_protocol, slotNumber - 1, pFdid[0].id);
209 + if (pDma != NULL) {
210 + pDevice->dev.dma_mask = &pDma->Mask;
211 + pDevice->dev.coherent_dma_mask = pDma->Mask;
213 + DBG_PRINT(SDDBG_ERROR,
214 + ("SDIO BusDriver - SDIO_GetBusOSDevice, registering driver: %s DMAmask: 0x%x\n",
215 + pDriver->name, (UINT)*pDevice->dev.dma_mask));
217 pDevice->protocol = &sdio_protocol;
218 pDevice->capabilities = PNP_REMOVABLE | PNP_DISABLE;
221 - /* set the id as slot number/function number */
222 - snprintf(id_name, sizeof(id_name) - 1, "SD_%02X08",
223 - 0); //??pDevice->pHcd->SlotNumber);//?????fix this, slotnumber isn't vaialble yet
224 - pnp_add_id(pDevice, id_name);
226 /* get a unique device number */
227 spin_lock(&InUseDevicesLock);
228 @@ -667,6 +668,7 @@ SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver,
230 /* replace the buggy pnp's release */
231 pDevice->dev.release = release;
232 + *outDevice = pDevice;
233 return OSErrorToSDIOError(err);
236 diff --git a/include/linux/sdio/sdio_busdriver.h b/include/linux/sdio/sdio_busdriver.h
237 index b431d3d..35e3ebb 100644
238 --- a/include/linux/sdio/sdio_busdriver.h
239 +++ b/include/linux/sdio/sdio_busdriver.h
240 @@ -477,7 +477,7 @@ typedef struct _SDDEVICE {
241 struct _SDHCD *pHcd; /* host controller this device is on (internal use) */
242 SDDEVICE_INFO DeviceInfo; /* device info */
243 SD_PNP_INFO pId[1]; /* id of this device */
244 - OS_PNPDEVICE Device; /* device registration with base system */
245 + OS_PNPDEVICE *Device; /* device registration with base system */
246 SD_SLOT_CURRENT SlotCurrentAlloc; /* allocated slot current for this device/function (internal use) */
247 SD_DEVICE_FLAGS Flags; /* internal use flags */
248 CT_VERSION_CODE Version; /* version code of the bus driver */
249 diff --git a/include/linux/sdio/sdio_hcd_defs.h b/include/linux/sdio/sdio_hcd_defs.h
250 index 1782469..e6115a2 100644
251 --- a/include/linux/sdio/sdio_hcd_defs.h
252 +++ b/include/linux/sdio/sdio_hcd_defs.h
253 @@ -213,7 +213,7 @@ SDIO_STATUS SDIO_RegisterHostController(PSDHCD pHcd);
254 SDIO_STATUS SDIO_UnregisterHostController(PSDHCD pHcd);
255 SDIO_STATUS SDIO_HandleHcdEvent(PSDHCD pHcd, HCD_EVENT Event);
256 SDIO_STATUS SDIO_CheckResponse(PSDHCD pHcd, PSDREQUEST pReq, SDHCD_RESPONSE_CHECK_MODE CheckMode);
257 -SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver, POS_PNPDEVICE pDevice);
258 +SDIO_STATUS SDIO_BusAddOSDevice(PSDDMA_DESCRIPTION pDma, POS_PNPDRIVER pDriver, POS_PNPDEVICE *pDevice, const char* name);
259 void SDIO_BusRemoveOSDevice(POS_PNPDRIVER pDriver, POS_PNPDEVICE pDevice);
261 #endif /* __SDIO_BUSDRIVER_H___ */