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

ARM: OMAP2+: mbox: remove dependencies with soc.h

The OMAP mailbox platform driver code has been cleaned up to
remove the dependencies with soc.h in preparation for moving
the mailbox code to drivers folder.

The code relied on cpu_is_xxx/soc_is_xxx macros previously to
pick the the right set of mailbox devices and register with the
mailbox driver. This data is now represented in a concise format
and moved to the respective omap_hwmod data files and published
to the driver through the platform data.

Cc: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Suman Anna <s-anna@ti.com>

+195 -169
+8 -1
arch/arm/mach-omap2/devices.c
··· 20 20 #include <linux/pinctrl/machine.h> 21 21 #include <linux/platform_data/omap4-keypad.h> 22 22 #include <linux/platform_data/omap_ocp2scp.h> 23 + #include <linux/platform_data/mailbox-omap.h> 23 24 #include <linux/usb/omap_control_usb.h> 24 25 25 26 #include <asm/mach-types.h> ··· 333 332 { 334 333 struct omap_hwmod *oh; 335 334 struct platform_device *pdev; 335 + struct omap_mbox_pdata *pdata; 336 336 337 337 oh = omap_hwmod_lookup("mailbox"); 338 338 if (!oh) { 339 339 pr_err("%s: unable to find hwmod\n", __func__); 340 340 return; 341 341 } 342 + if (!oh->dev_attr) { 343 + pr_err("%s: hwmod doesn't have valid attrs\n", __func__); 344 + return; 345 + } 342 346 343 - pdev = omap_device_build("omap-mailbox", -1, oh, NULL, 0); 347 + pdata = (struct omap_mbox_pdata *)oh->dev_attr; 348 + pdev = omap_device_build("omap-mailbox", -1, oh, pdata, sizeof(*pdata)); 344 349 WARN(IS_ERR(pdev), "%s: could not build device, err %ld\n", 345 350 __func__, PTR_ERR(pdev)); 346 351 }
+99 -167
arch/arm/mach-omap2/mailbox.c
··· 11 11 */ 12 12 13 13 #include <linux/module.h> 14 + #include <linux/slab.h> 14 15 #include <linux/clk.h> 15 16 #include <linux/err.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/io.h> 18 19 #include <linux/pm_runtime.h> 20 + #include <linux/platform_data/mailbox-omap.h> 19 21 20 22 #include <plat/mailbox.h> 21 - 22 - #include "soc.h" 23 23 24 24 #define MAILBOX_REVISION 0x000 25 25 #define MAILBOX_MESSAGE(m) (0x040 + 4 * (m)) ··· 59 59 u32 notfull_bit; 60 60 u32 ctx[OMAP4_MBOX_NR_REGS]; 61 61 unsigned long irqdisable; 62 + u32 intr_type; 62 63 }; 63 64 64 65 static inline unsigned int mbox_read_reg(size_t ofs) ··· 137 136 struct omap_mbox2_priv *p = mbox->priv; 138 137 u32 bit = (irq == IRQ_TX) ? p->notfull_bit : p->newmsg_bit; 139 138 140 - if (!cpu_is_omap44xx()) 139 + /* 140 + * Read and update the interrupt configuration register for pre-OMAP4. 141 + * OMAP4 and later SoCs have a dedicated interrupt disabling register. 142 + */ 143 + if (!p->intr_type) 141 144 bit = mbox_read_reg(p->irqdisable) & ~bit; 142 145 143 146 mbox_write_reg(bit, p->irqdisable); ··· 173 168 int i; 174 169 struct omap_mbox2_priv *p = mbox->priv; 175 170 int nr_regs; 176 - if (cpu_is_omap44xx()) 171 + 172 + if (p->intr_type) 177 173 nr_regs = OMAP4_MBOX_NR_REGS; 178 174 else 179 175 nr_regs = MBOX_NR_REGS; ··· 191 185 int i; 192 186 struct omap_mbox2_priv *p = mbox->priv; 193 187 int nr_regs; 194 - if (cpu_is_omap44xx()) 188 + 189 + if (p->intr_type) 195 190 nr_regs = OMAP4_MBOX_NR_REGS; 196 191 else 197 192 nr_regs = MBOX_NR_REGS; ··· 220 213 .restore_ctx = omap2_mbox_restore_ctx, 221 214 }; 222 215 223 - /* 224 - * MAILBOX 0: ARM -> DSP, 225 - * MAILBOX 1: ARM <- DSP. 226 - * MAILBOX 2: ARM -> IVA, 227 - * MAILBOX 3: ARM <- IVA. 228 - */ 229 - 230 - /* FIXME: the following structs should be filled automatically by the user id */ 231 - 232 - #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP2) 233 - /* DSP */ 234 - static struct omap_mbox2_priv omap2_mbox_dsp_priv = { 235 - .tx_fifo = { 236 - .msg = MAILBOX_MESSAGE(0), 237 - .fifo_stat = MAILBOX_FIFOSTATUS(0), 238 - }, 239 - .rx_fifo = { 240 - .msg = MAILBOX_MESSAGE(1), 241 - .msg_stat = MAILBOX_MSGSTATUS(1), 242 - }, 243 - .irqenable = MAILBOX_IRQENABLE(0), 244 - .irqstatus = MAILBOX_IRQSTATUS(0), 245 - .notfull_bit = MAILBOX_IRQ_NOTFULL(0), 246 - .newmsg_bit = MAILBOX_IRQ_NEWMSG(1), 247 - .irqdisable = MAILBOX_IRQENABLE(0), 248 - }; 249 - 250 - struct omap_mbox mbox_dsp_info = { 251 - .name = "dsp", 252 - .ops = &omap2_mbox_ops, 253 - .priv = &omap2_mbox_dsp_priv, 254 - }; 255 - #endif 256 - 257 - #if defined(CONFIG_ARCH_OMAP3) 258 - struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL }; 259 - #endif 260 - 261 - #if defined(CONFIG_SOC_OMAP2420) 262 - /* IVA */ 263 - static struct omap_mbox2_priv omap2_mbox_iva_priv = { 264 - .tx_fifo = { 265 - .msg = MAILBOX_MESSAGE(2), 266 - .fifo_stat = MAILBOX_FIFOSTATUS(2), 267 - }, 268 - .rx_fifo = { 269 - .msg = MAILBOX_MESSAGE(3), 270 - .msg_stat = MAILBOX_MSGSTATUS(3), 271 - }, 272 - .irqenable = MAILBOX_IRQENABLE(3), 273 - .irqstatus = MAILBOX_IRQSTATUS(3), 274 - .notfull_bit = MAILBOX_IRQ_NOTFULL(2), 275 - .newmsg_bit = MAILBOX_IRQ_NEWMSG(3), 276 - .irqdisable = MAILBOX_IRQENABLE(3), 277 - }; 278 - 279 - static struct omap_mbox mbox_iva_info = { 280 - .name = "iva", 281 - .ops = &omap2_mbox_ops, 282 - .priv = &omap2_mbox_iva_priv, 283 - }; 284 - #endif 285 - 286 - #ifdef CONFIG_ARCH_OMAP2 287 - struct omap_mbox *omap2_mboxes[] = { 288 - &mbox_dsp_info, 289 - #ifdef CONFIG_SOC_OMAP2420 290 - &mbox_iva_info, 291 - #endif 292 - NULL 293 - }; 294 - #endif 295 - 296 - #if defined(CONFIG_ARCH_OMAP4) 297 - /* OMAP4 */ 298 - static struct omap_mbox2_priv omap2_mbox_1_priv = { 299 - .tx_fifo = { 300 - .msg = MAILBOX_MESSAGE(0), 301 - .fifo_stat = MAILBOX_FIFOSTATUS(0), 302 - }, 303 - .rx_fifo = { 304 - .msg = MAILBOX_MESSAGE(1), 305 - .msg_stat = MAILBOX_MSGSTATUS(1), 306 - }, 307 - .irqenable = OMAP4_MAILBOX_IRQENABLE(0), 308 - .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0), 309 - .notfull_bit = MAILBOX_IRQ_NOTFULL(0), 310 - .newmsg_bit = MAILBOX_IRQ_NEWMSG(1), 311 - .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0), 312 - }; 313 - 314 - struct omap_mbox mbox_1_info = { 315 - .name = "mailbox-1", 316 - .ops = &omap2_mbox_ops, 317 - .priv = &omap2_mbox_1_priv, 318 - }; 319 - 320 - static struct omap_mbox2_priv omap2_mbox_2_priv = { 321 - .tx_fifo = { 322 - .msg = MAILBOX_MESSAGE(3), 323 - .fifo_stat = MAILBOX_FIFOSTATUS(3), 324 - }, 325 - .rx_fifo = { 326 - .msg = MAILBOX_MESSAGE(2), 327 - .msg_stat = MAILBOX_MSGSTATUS(2), 328 - }, 329 - .irqenable = OMAP4_MAILBOX_IRQENABLE(0), 330 - .irqstatus = OMAP4_MAILBOX_IRQSTATUS(0), 331 - .notfull_bit = MAILBOX_IRQ_NOTFULL(3), 332 - .newmsg_bit = MAILBOX_IRQ_NEWMSG(2), 333 - .irqdisable = OMAP4_MAILBOX_IRQENABLE_CLR(0), 334 - }; 335 - 336 - struct omap_mbox mbox_2_info = { 337 - .name = "mailbox-2", 338 - .ops = &omap2_mbox_ops, 339 - .priv = &omap2_mbox_2_priv, 340 - }; 341 - 342 - struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL }; 343 - #endif 344 - 345 216 static int omap2_mbox_probe(struct platform_device *pdev) 346 217 { 347 218 struct resource *mem; 348 219 int ret; 349 - struct omap_mbox **list; 220 + struct omap_mbox **list, *mbox, *mboxblk; 221 + struct omap_mbox2_priv *priv, *privblk; 222 + struct omap_mbox_pdata *pdata = pdev->dev.platform_data; 223 + struct omap_mbox_dev_info *info; 224 + int i; 350 225 351 - if (false) 352 - ; 353 - #if defined(CONFIG_ARCH_OMAP3) 354 - else if (cpu_is_omap34xx()) { 355 - list = omap3_mboxes; 356 - 357 - list[0]->irq = platform_get_irq(pdev, 0); 358 - } 359 - #endif 360 - #if defined(CONFIG_ARCH_OMAP2) 361 - else if (cpu_is_omap2430()) { 362 - list = omap2_mboxes; 363 - 364 - list[0]->irq = platform_get_irq(pdev, 0); 365 - } else if (cpu_is_omap2420()) { 366 - list = omap2_mboxes; 367 - 368 - list[0]->irq = platform_get_irq_byname(pdev, "dsp"); 369 - list[1]->irq = platform_get_irq_byname(pdev, "iva"); 370 - } 371 - #endif 372 - #if defined(CONFIG_ARCH_OMAP4) 373 - else if (cpu_is_omap44xx()) { 374 - list = omap4_mboxes; 375 - 376 - list[0]->irq = list[1]->irq = platform_get_irq(pdev, 0); 377 - } 378 - #endif 379 - else { 226 + if (!pdata || !pdata->info_cnt || !pdata->info) { 380 227 pr_err("%s: platform not supported\n", __func__); 381 228 return -ENODEV; 382 229 } 383 230 384 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 385 - if (!mem) 386 - return -ENOENT; 387 - 388 - mbox_base = ioremap(mem->start, resource_size(mem)); 389 - if (!mbox_base) 231 + /* allocate one extra for marking end of list */ 232 + list = kzalloc((pdata->info_cnt + 1) * sizeof(*list), GFP_KERNEL); 233 + if (!list) 390 234 return -ENOMEM; 391 235 392 - ret = omap_mbox_register(&pdev->dev, list); 393 - if (ret) { 394 - iounmap(mbox_base); 395 - return ret; 236 + mboxblk = mbox = kzalloc(pdata->info_cnt * sizeof(*mbox), GFP_KERNEL); 237 + if (!mboxblk) { 238 + ret = -ENOMEM; 239 + goto free_list; 396 240 } 397 241 242 + privblk = priv = kzalloc(pdata->info_cnt * sizeof(*priv), GFP_KERNEL); 243 + if (!privblk) { 244 + ret = -ENOMEM; 245 + goto free_mboxblk; 246 + } 247 + 248 + info = pdata->info; 249 + for (i = 0; i < pdata->info_cnt; i++, info++, priv++) { 250 + priv->tx_fifo.msg = MAILBOX_MESSAGE(info->tx_id); 251 + priv->tx_fifo.fifo_stat = MAILBOX_FIFOSTATUS(info->tx_id); 252 + priv->rx_fifo.msg = MAILBOX_MESSAGE(info->rx_id); 253 + priv->rx_fifo.msg_stat = MAILBOX_MSGSTATUS(info->rx_id); 254 + priv->notfull_bit = MAILBOX_IRQ_NOTFULL(info->tx_id); 255 + priv->newmsg_bit = MAILBOX_IRQ_NEWMSG(info->rx_id); 256 + if (pdata->intr_type) { 257 + priv->irqenable = OMAP4_MAILBOX_IRQENABLE(info->usr_id); 258 + priv->irqstatus = OMAP4_MAILBOX_IRQSTATUS(info->usr_id); 259 + priv->irqdisable = 260 + OMAP4_MAILBOX_IRQENABLE_CLR(info->usr_id); 261 + } else { 262 + priv->irqenable = MAILBOX_IRQENABLE(info->usr_id); 263 + priv->irqstatus = MAILBOX_IRQSTATUS(info->usr_id); 264 + priv->irqdisable = MAILBOX_IRQENABLE(info->usr_id); 265 + } 266 + priv->intr_type = pdata->intr_type; 267 + 268 + mbox->priv = priv; 269 + mbox->name = info->name; 270 + mbox->ops = &omap2_mbox_ops; 271 + mbox->irq = platform_get_irq(pdev, info->irq_id); 272 + if (mbox->irq < 0) { 273 + ret = mbox->irq; 274 + goto free_privblk; 275 + } 276 + list[i] = mbox++; 277 + } 278 + 279 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 280 + if (!mem) { 281 + ret = -ENOENT; 282 + goto free_privblk; 283 + } 284 + 285 + mbox_base = ioremap(mem->start, resource_size(mem)); 286 + if (!mbox_base) { 287 + ret = -ENOMEM; 288 + goto free_privblk; 289 + } 290 + 291 + ret = omap_mbox_register(&pdev->dev, list); 292 + if (ret) 293 + goto unmap_mbox; 294 + platform_set_drvdata(pdev, list); 295 + 398 296 return 0; 297 + 298 + unmap_mbox: 299 + iounmap(mbox_base); 300 + free_privblk: 301 + kfree(privblk); 302 + free_mboxblk: 303 + kfree(mboxblk); 304 + free_list: 305 + kfree(list); 306 + return ret; 399 307 } 400 308 401 309 static int omap2_mbox_remove(struct platform_device *pdev) 402 310 { 311 + struct omap_mbox2_priv *privblk; 312 + struct omap_mbox **list = platform_get_drvdata(pdev); 313 + struct omap_mbox *mboxblk = list[0]; 314 + 315 + privblk = mboxblk->priv; 403 316 omap_mbox_unregister(); 404 317 iounmap(mbox_base); 318 + kfree(privblk); 319 + kfree(mboxblk); 320 + kfree(list); 321 + platform_set_drvdata(pdev, NULL); 322 + 405 323 return 0; 406 324 } 407 325
+12
arch/arm/mach-omap2/omap_hwmod_2420_data.c
··· 16 16 #include <linux/i2c-omap.h> 17 17 #include <linux/platform_data/spi-omap2-mcspi.h> 18 18 #include <linux/omap-dma.h> 19 + #include <linux/platform_data/mailbox-omap.h> 19 20 #include <plat/dmtimer.h> 20 21 21 22 #include "omap_hwmod.h" ··· 167 166 }; 168 167 169 168 /* mailbox */ 169 + static struct omap_mbox_dev_info omap2420_mailbox_info[] = { 170 + { .name = "dsp", .tx_id = 0, .rx_id = 1, .irq_id = 0, .usr_id = 0 }, 171 + { .name = "iva", .tx_id = 2, .rx_id = 3, .irq_id = 1, .usr_id = 3 }, 172 + }; 173 + 174 + static struct omap_mbox_pdata omap2420_mailbox_attrs = { 175 + .info_cnt = ARRAY_SIZE(omap2420_mailbox_info), 176 + .info = omap2420_mailbox_info, 177 + }; 178 + 170 179 static struct omap_hwmod_irq_info omap2420_mailbox_irqs[] = { 171 180 { .name = "dsp", .irq = 26 + OMAP_INTC_START, }, 172 181 { .name = "iva", .irq = 34 + OMAP_INTC_START, }, ··· 197 186 .idlest_idle_bit = OMAP24XX_ST_MAILBOXES_SHIFT, 198 187 }, 199 188 }, 189 + .dev_attr = &omap2420_mailbox_attrs, 200 190 }; 201 191 202 192 /*
+11
arch/arm/mach-omap2/omap_hwmod_2430_data.c
··· 17 17 #include <linux/platform_data/asoc-ti-mcbsp.h> 18 18 #include <linux/platform_data/spi-omap2-mcspi.h> 19 19 #include <linux/omap-dma.h> 20 + #include <linux/platform_data/mailbox-omap.h> 20 21 #include <plat/dmtimer.h> 21 22 22 23 #include "omap_hwmod.h" ··· 171 170 }; 172 171 173 172 /* mailbox */ 173 + static struct omap_mbox_dev_info omap2430_mailbox_info[] = { 174 + { .name = "dsp", .tx_id = 0, .rx_id = 1 }, 175 + }; 176 + 177 + static struct omap_mbox_pdata omap2430_mailbox_attrs = { 178 + .info_cnt = ARRAY_SIZE(omap2430_mailbox_info), 179 + .info = omap2430_mailbox_info, 180 + }; 181 + 174 182 static struct omap_hwmod_irq_info omap2430_mailbox_irqs[] = { 175 183 { .irq = 26 + OMAP_INTC_START, }, 176 184 { .irq = -1 }, ··· 199 189 .idlest_idle_bit = OMAP24XX_ST_MAILBOXES_SHIFT, 200 190 }, 201 191 }, 192 + .dev_attr = &omap2430_mailbox_attrs, 202 193 }; 203 194 204 195 /* mcspi3 */
+11
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
··· 25 25 #include <linux/platform_data/asoc-ti-mcbsp.h> 26 26 #include <linux/platform_data/spi-omap2-mcspi.h> 27 27 #include <linux/platform_data/iommu-omap.h> 28 + #include <linux/platform_data/mailbox-omap.h> 28 29 #include <plat/dmtimer.h> 29 30 30 31 #include "am35xx.h" ··· 1506 1505 .sysc = &omap3xxx_mailbox_sysc, 1507 1506 }; 1508 1507 1508 + static struct omap_mbox_dev_info omap3xxx_mailbox_info[] = { 1509 + { .name = "dsp", .tx_id = 0, .rx_id = 1 }, 1510 + }; 1511 + 1512 + static struct omap_mbox_pdata omap3xxx_mailbox_attrs = { 1513 + .info_cnt = ARRAY_SIZE(omap3xxx_mailbox_info), 1514 + .info = omap3xxx_mailbox_info, 1515 + }; 1516 + 1509 1517 static struct omap_hwmod_irq_info omap3xxx_mailbox_irqs[] = { 1510 1518 { .irq = 26 + OMAP_INTC_START, }, 1511 1519 { .irq = -1 }, ··· 1534 1524 .idlest_idle_bit = OMAP3430_ST_MAILBOXES_SHIFT, 1535 1525 }, 1536 1526 }, 1527 + .dev_attr = &omap3xxx_mailbox_attrs, 1537 1528 }; 1538 1529 1539 1530 /*
+1 -1
arch/arm/plat-omap/include/plat/mailbox.h
··· 51 51 }; 52 52 53 53 struct omap_mbox { 54 - char *name; 54 + const char *name; 55 55 unsigned int irq; 56 56 struct omap_mbox_queue *txq, *rxq; 57 57 struct omap_mbox_ops *ops;
+53
include/linux/platform_data/mailbox-omap.h
··· 1 + /* 2 + * mailbox-omap.h 3 + * 4 + * Copyright (C) 2013 Texas Instruments, Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License 8 + * version 2 as published by the Free Software Foundation. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + */ 15 + 16 + #ifndef _PLAT_MAILBOX_H 17 + #define _PLAT_MAILBOX_H 18 + 19 + /* Interrupt register configuration types */ 20 + #define MBOX_INTR_CFG_TYPE1 (0) 21 + #define MBOX_INTR_CFG_TYPE2 (1) 22 + 23 + /** 24 + * struct omap_mbox_dev_info - OMAP mailbox device attribute info 25 + * @name: name of the mailbox device 26 + * @tx_id: mailbox queue id used for transmitting messages 27 + * @rx_id: mailbox queue id on which messages are received 28 + * @irq_id: irq identifier number to use from the hwmod data 29 + * @usr_id: mailbox user id for identifying the interrupt into 30 + * the MPU interrupt controller. 31 + */ 32 + struct omap_mbox_dev_info { 33 + const char *name; 34 + u32 tx_id; 35 + u32 rx_id; 36 + u32 irq_id; 37 + u32 usr_id; 38 + }; 39 + 40 + /** 41 + * struct omap_mbox_pdata - OMAP mailbox platform data 42 + * @intr_type: type of interrupt configuration registers used 43 + while programming mailbox queue interrupts 44 + * @info_cnt: number of mailbox devices for the platform 45 + * @info: array of mailbox device attributes 46 + */ 47 + struct omap_mbox_pdata { 48 + u32 intr_type; 49 + u32 info_cnt; 50 + struct omap_mbox_dev_info *info; 51 + }; 52 + 53 + #endif /* _PLAT_MAILBOX_H */