aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/sh_mobile_meram.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-09-19 05:40:31 -0400
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-03-12 17:41:10 -0400
commit7554340c7acae4a719b1b70b0defa3c67149610b (patch)
treecf3fb0d2fd28fdfe2d2e48b9951b7fd2f3e67b7a /drivers/video/sh_mobile_meram.c
parent762f7cc94bc5c5c8c54f9d0073a07a275b106d89 (diff)
fbdev: sh_mobile_meram: Divide the code into sections
And rename a couple of constants to make prefixes more uniform. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'drivers/video/sh_mobile_meram.c')
-rw-r--r--drivers/video/sh_mobile_meram.c98
1 files changed, 44 insertions, 54 deletions
diff --git a/drivers/video/sh_mobile_meram.c b/drivers/video/sh_mobile_meram.c
index 0c5b301697e1..30a3305ba366 100644
--- a/drivers/video/sh_mobile_meram.c
+++ b/drivers/video/sh_mobile_meram.c
@@ -9,16 +9,20 @@
9 * for more details. 9 * for more details.
10 */ 10 */
11 11
12#include <linux/device.h>
13#include <linux/io.h>
12#include <linux/kernel.h> 14#include <linux/kernel.h>
13#include <linux/module.h> 15#include <linux/module.h>
14#include <linux/device.h> 16#include <linux/platform_device.h>
15#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
16#include <linux/io.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/platform_device.h> 19
19#include <video/sh_mobile_meram.h> 20#include <video/sh_mobile_meram.h>
20 21
21/* meram registers */ 22/* -----------------------------------------------------------------------------
23 * MERAM registers
24 */
25
22#define MEVCR1 0x4 26#define MEVCR1 0x4
23#define MEVCR1_RST (1 << 31) 27#define MEVCR1_RST (1 << 31)
24#define MEVCR1_WD (1 << 30) 28#define MEVCR1_WD (1 << 30)
@@ -81,14 +85,12 @@
81 ((yszm1) << MExxBSIZE_YSZM1_SHIFT) | \ 85 ((yszm1) << MExxBSIZE_YSZM1_SHIFT) | \
82 ((xszm1) << MExxBSIZE_XSZM1_SHIFT)) 86 ((xszm1) << MExxBSIZE_XSZM1_SHIFT))
83 87
84#define SH_MOBILE_MERAM_ICB_NUM 32
85
86static const unsigned long common_regs[] = { 88static const unsigned long common_regs[] = {
87 MEVCR1, 89 MEVCR1,
88 MEQSEL1, 90 MEQSEL1,
89 MEQSEL2, 91 MEQSEL2,
90}; 92};
91#define CMN_REGS_SIZE ARRAY_SIZE(common_regs) 93#define MERAM_REGS_SIZE ARRAY_SIZE(common_regs)
92 94
93static const unsigned long icb_regs[] = { 95static const unsigned long icb_regs[] = {
94 MExxCTL, 96 MExxCTL,
@@ -117,6 +119,8 @@ struct sh_mobile_meram_icb {
117 unsigned int current_reg; 119 unsigned int current_reg;
118}; 120};
119 121
122#define MERAM_ICB_NUM 32
123
120/* 124/*
121 * sh_mobile_meram_priv - MERAM device 125 * sh_mobile_meram_priv - MERAM device
122 * @base: Registers base address 126 * @base: Registers base address
@@ -127,19 +131,19 @@ struct sh_mobile_meram_icb {
127 */ 131 */
128struct sh_mobile_meram_priv { 132struct sh_mobile_meram_priv {
129 void __iomem *base; 133 void __iomem *base;
130 unsigned long regs[CMN_REGS_SIZE]; 134 unsigned long regs[MERAM_REGS_SIZE];
131 135
132 struct mutex lock; 136 struct mutex lock;
133 unsigned long used_icb; 137 unsigned long used_icb;
134 struct sh_mobile_meram_icb icbs[SH_MOBILE_MERAM_ICB_NUM]; 138 struct sh_mobile_meram_icb icbs[MERAM_ICB_NUM];
135}; 139};
136 140
137/* settings */ 141/* settings */
138#define MERAM_SEC_LINE 15 142#define MERAM_SEC_LINE 15
139#define MERAM_LINE_WIDTH 2048 143#define MERAM_LINE_WIDTH 2048
140 144
141/* 145/* -----------------------------------------------------------------------------
142 * MERAM/ICB access functions 146 * Registers access
143 */ 147 */
144 148
145#define MERAM_ICB_OFFSET(base, idx, off) ((base) + (off) + (idx) * 0x20) 149#define MERAM_ICB_OFFSET(base, idx, off) ((base) + (off) + (idx) * 0x20)
@@ -167,8 +171,8 @@ static inline unsigned long meram_read_reg(void __iomem *base, unsigned int off)
167 return ioread32(base + off); 171 return ioread32(base + off);
168} 172}
169 173
170/* 174/* -----------------------------------------------------------------------------
171 * register ICB 175 * Allocation
172 */ 176 */
173 177
174#define MERAM_CACHE_START(p) ((p) >> 16) 178#define MERAM_CACHE_START(p) ((p) >> 16)
@@ -176,10 +180,7 @@ static inline unsigned long meram_read_reg(void __iomem *base, unsigned int off)
176#define MERAM_CACHE_SET(o, s) ((((o) & 0xffff) << 16) | \ 180#define MERAM_CACHE_SET(o, s) ((((o) & 0xffff) << 16) | \
177 (((o) + (s) - 1) & 0xffff)) 181 (((o) + (s) - 1) & 0xffff))
178 182
179/* 183/* Check if there's no overlaps in MERAM allocation. */
180 * check if there's no overlaps in MERAM allocation.
181 */
182
183static int meram_check_overlap(struct sh_mobile_meram_priv *priv, 184static int meram_check_overlap(struct sh_mobile_meram_priv *priv,
184 const struct sh_mobile_meram_icb_cfg *new) 185 const struct sh_mobile_meram_icb_cfg *new)
185{ 186{
@@ -194,7 +195,7 @@ static int meram_check_overlap(struct sh_mobile_meram_priv *priv,
194 test_bit(new->cache_icb, &priv->used_icb)) 195 test_bit(new->cache_icb, &priv->used_icb))
195 return 1; 196 return 1;
196 197
197 for (i = 0; i < SH_MOBILE_MERAM_ICB_NUM; i++) { 198 for (i = 0; i < MERAM_ICB_NUM; i++) {
198 if (!test_bit(i, &priv->used_icb)) 199 if (!test_bit(i, &priv->used_icb))
199 continue; 200 continue;
200 201
@@ -211,10 +212,7 @@ static int meram_check_overlap(struct sh_mobile_meram_priv *priv,
211 return 0; 212 return 0;
212} 213}
213 214
214/* 215/* Mark the specified ICB as used. */
215 * mark the specified ICB as used
216 */
217
218static void meram_mark(struct sh_mobile_meram_priv *priv, 216static void meram_mark(struct sh_mobile_meram_priv *priv,
219 const struct sh_mobile_meram_icb_cfg *new, 217 const struct sh_mobile_meram_icb_cfg *new,
220 int pixelformat) 218 int pixelformat)
@@ -230,10 +228,7 @@ static void meram_mark(struct sh_mobile_meram_priv *priv,
230 priv->icbs[new->marker_icb].pixelformat = pixelformat; 228 priv->icbs[new->marker_icb].pixelformat = pixelformat;
231} 229}
232 230
233/* 231/* Unmark the specified ICB as used. */
234 * unmark the specified ICB as used
235 */
236
237static void meram_unmark(struct sh_mobile_meram_priv *priv, 232static void meram_unmark(struct sh_mobile_meram_priv *priv,
238 const struct sh_mobile_meram_icb_cfg *icb) 233 const struct sh_mobile_meram_icb_cfg *icb)
239{ 234{
@@ -241,9 +236,7 @@ static void meram_unmark(struct sh_mobile_meram_priv *priv,
241 __clear_bit(icb->cache_icb, &priv->used_icb); 236 __clear_bit(icb->cache_icb, &priv->used_icb);
242} 237}
243 238
244/* 239/* Is this a YCbCr(NV12, NV16 or NV24) colorspace? */
245 * is this a YCbCr(NV12, NV16 or NV24) colorspace
246 */
247static int is_nvcolor(int cspace) 240static int is_nvcolor(int cspace)
248{ 241{
249 if (cspace == SH_MOBILE_MERAM_PF_NV || 242 if (cspace == SH_MOBILE_MERAM_PF_NV ||
@@ -252,9 +245,7 @@ static int is_nvcolor(int cspace)
252 return 0; 245 return 0;
253} 246}
254 247
255/* 248/* Set the next address to fetch. */
256 * set the next address to fetch
257 */
258static void meram_set_next_addr(struct sh_mobile_meram_priv *priv, 249static void meram_set_next_addr(struct sh_mobile_meram_priv *priv,
259 const struct sh_mobile_meram_cfg *cfg, 250 const struct sh_mobile_meram_cfg *cfg,
260 unsigned long base_addr_y, 251 unsigned long base_addr_y,
@@ -282,9 +273,7 @@ static void meram_set_next_addr(struct sh_mobile_meram_priv *priv,
282 } 273 }
283} 274}
284 275
285/* 276/* Get the next ICB address. */
286 * get the next ICB address
287 */
288static void 277static void
289meram_get_next_icb_addr(struct sh_mobile_meram_info *pdata, 278meram_get_next_icb_addr(struct sh_mobile_meram_info *pdata,
290 const struct sh_mobile_meram_cfg *cfg, 279 const struct sh_mobile_meram_cfg *cfg,
@@ -307,10 +296,7 @@ meram_get_next_icb_addr(struct sh_mobile_meram_info *pdata,
307#define MERAM_CALC_BYTECOUNT(x, y) \ 296#define MERAM_CALC_BYTECOUNT(x, y) \
308 (((x) * (y) + (MERAM_LINE_WIDTH - 1)) & ~(MERAM_LINE_WIDTH - 1)) 297 (((x) * (y) + (MERAM_LINE_WIDTH - 1)) & ~(MERAM_LINE_WIDTH - 1))
309 298
310/* 299/* Initialize MERAM. */
311 * initialize MERAM
312 */
313
314static int meram_init(struct sh_mobile_meram_priv *priv, 300static int meram_init(struct sh_mobile_meram_priv *priv,
315 const struct sh_mobile_meram_icb_cfg *icb, 301 const struct sh_mobile_meram_icb_cfg *icb,
316 unsigned int xres, unsigned int yres, 302 unsigned int xres, unsigned int yres,
@@ -395,8 +381,8 @@ static void meram_deinit(struct sh_mobile_meram_priv *priv,
395 priv->icbs[icb->marker_icb].cache_unit = 0; 381 priv->icbs[icb->marker_icb].cache_unit = 0;
396} 382}
397 383
398/* 384/* -----------------------------------------------------------------------------
399 * register the ICB 385 * Registration/unregistration
400 */ 386 */
401 387
402static int sh_mobile_meram_register(struct sh_mobile_meram_info *pdata, 388static int sh_mobile_meram_register(struct sh_mobile_meram_info *pdata,
@@ -545,13 +531,24 @@ static int sh_mobile_meram_update(struct sh_mobile_meram_info *pdata,
545 return 0; 531 return 0;
546} 532}
547 533
534static struct sh_mobile_meram_ops sh_mobile_meram_ops = {
535 .module = THIS_MODULE,
536 .meram_register = sh_mobile_meram_register,
537 .meram_unregister = sh_mobile_meram_unregister,
538 .meram_update = sh_mobile_meram_update,
539};
540
541/* -----------------------------------------------------------------------------
542 * Power management
543 */
544
548static int sh_mobile_meram_runtime_suspend(struct device *dev) 545static int sh_mobile_meram_runtime_suspend(struct device *dev)
549{ 546{
550 struct platform_device *pdev = to_platform_device(dev); 547 struct platform_device *pdev = to_platform_device(dev);
551 struct sh_mobile_meram_priv *priv = platform_get_drvdata(pdev); 548 struct sh_mobile_meram_priv *priv = platform_get_drvdata(pdev);
552 unsigned int i, j; 549 unsigned int i, j;
553 550
554 for (i = 0; i < CMN_REGS_SIZE; i++) 551 for (i = 0; i < MERAM_REGS_SIZE; i++)
555 priv->regs[i] = meram_read_reg(priv->base, common_regs[i]); 552 priv->regs[i] = meram_read_reg(priv->base, common_regs[i]);
556 553
557 for (i = 0; i < 32; i++) { 554 for (i = 0; i < 32; i++) {
@@ -583,7 +580,7 @@ static int sh_mobile_meram_runtime_resume(struct device *dev)
583 priv->icbs[i].regs[j]); 580 priv->icbs[i].regs[j]);
584 } 581 }
585 582
586 for (i = 0; i < CMN_REGS_SIZE; i++) 583 for (i = 0; i < MERAM_REGS_SIZE; i++)
587 meram_write_reg(priv->base, common_regs[i], priv->regs[i]); 584 meram_write_reg(priv->base, common_regs[i], priv->regs[i]);
588 return 0; 585 return 0;
589} 586}
@@ -593,15 +590,8 @@ static const struct dev_pm_ops sh_mobile_meram_dev_pm_ops = {
593 .runtime_resume = sh_mobile_meram_runtime_resume, 590 .runtime_resume = sh_mobile_meram_runtime_resume,
594}; 591};
595 592
596static struct sh_mobile_meram_ops sh_mobile_meram_ops = { 593/* -----------------------------------------------------------------------------
597 .module = THIS_MODULE, 594 * Probe/remove and driver init/exit
598 .meram_register = sh_mobile_meram_register,
599 .meram_unregister = sh_mobile_meram_unregister,
600 .meram_update = sh_mobile_meram_update,
601};
602
603/*
604 * initialize MERAM
605 */ 595 */
606 596
607static int __devinit sh_mobile_meram_probe(struct platform_device *pdev) 597static int __devinit sh_mobile_meram_probe(struct platform_device *pdev)