xref: /openbmc/linux/drivers/video/fbdev/bt455.h (revision 5832706e)
1f7018c21STomi Valkeinen /*
2f7018c21STomi Valkeinen  *	linux/drivers/video/bt455.h
3f7018c21STomi Valkeinen  *
4f7018c21STomi Valkeinen  *	Copyright 2003  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
501ac59c3SMaciej W. Rozycki  *	Copyright 2016  Maciej W. Rozycki <macro@linux-mips.org>
6f7018c21STomi Valkeinen  *
7f7018c21STomi Valkeinen  *	This file is subject to the terms and conditions of the GNU General
8f7018c21STomi Valkeinen  *	Public License. See the file COPYING in the main directory of this
9f7018c21STomi Valkeinen  *	archive for more details.
10f7018c21STomi Valkeinen  */
11f7018c21STomi Valkeinen #include <linux/types.h>
12f7018c21STomi Valkeinen 
13f7018c21STomi Valkeinen /*
14f7018c21STomi Valkeinen  * Bt455 byte-wide registers, 32-bit aligned.
15f7018c21STomi Valkeinen  */
16f7018c21STomi Valkeinen struct bt455_regs {
17f7018c21STomi Valkeinen 	volatile u8 addr_cmap;
18f7018c21STomi Valkeinen 	u8 pad0[3];
19f7018c21STomi Valkeinen 	volatile u8 addr_cmap_data;
20f7018c21STomi Valkeinen 	u8 pad1[3];
21f7018c21STomi Valkeinen 	volatile u8 addr_clr;
22f7018c21STomi Valkeinen 	u8 pad2[3];
23f7018c21STomi Valkeinen 	volatile u8 addr_ovly;
24f7018c21STomi Valkeinen 	u8 pad3[3];
25f7018c21STomi Valkeinen };
26f7018c21STomi Valkeinen 
bt455_select_reg(struct bt455_regs * regs,int ir)27f7018c21STomi Valkeinen static inline void bt455_select_reg(struct bt455_regs *regs, int ir)
28f7018c21STomi Valkeinen {
29f7018c21STomi Valkeinen 	mb();
30f7018c21STomi Valkeinen 	regs->addr_cmap = ir & 0x0f;
31f7018c21STomi Valkeinen }
32f7018c21STomi Valkeinen 
bt455_reset_reg(struct bt455_regs * regs)335832706eSMaciej W. Rozycki static inline void bt455_reset_reg(struct bt455_regs *regs)
345832706eSMaciej W. Rozycki {
355832706eSMaciej W. Rozycki 	mb();
365832706eSMaciej W. Rozycki 	regs->addr_clr = 0;
375832706eSMaciej W. Rozycki }
385832706eSMaciej W. Rozycki 
39f7018c21STomi Valkeinen /*
40f7018c21STomi Valkeinen  * Read/write to a Bt455 color map register.
41f7018c21STomi Valkeinen  */
bt455_read_cmap_next(struct bt455_regs * regs,u8 * grey)425832706eSMaciej W. Rozycki static inline void bt455_read_cmap_next(struct bt455_regs *regs, u8 *grey)
43f7018c21STomi Valkeinen {
44f7018c21STomi Valkeinen 	mb();
4501ac59c3SMaciej W. Rozycki 	regs->addr_cmap_data;
46f7018c21STomi Valkeinen 	rmb();
4701ac59c3SMaciej W. Rozycki 	*grey = regs->addr_cmap_data & 0xf;
48f7018c21STomi Valkeinen 	rmb();
4901ac59c3SMaciej W. Rozycki 	regs->addr_cmap_data;
50f7018c21STomi Valkeinen }
51f7018c21STomi Valkeinen 
bt455_write_cmap_next(struct bt455_regs * regs,u8 grey)525832706eSMaciej W. Rozycki static inline void bt455_write_cmap_next(struct bt455_regs *regs, u8 grey)
53f7018c21STomi Valkeinen {
54f7018c21STomi Valkeinen 	wmb();
5501ac59c3SMaciej W. Rozycki 	regs->addr_cmap_data = 0x0;
56f7018c21STomi Valkeinen 	wmb();
5701ac59c3SMaciej W. Rozycki 	regs->addr_cmap_data = grey & 0xf;
58f7018c21STomi Valkeinen 	wmb();
5901ac59c3SMaciej W. Rozycki 	regs->addr_cmap_data = 0x0;
60f7018c21STomi Valkeinen }
61f7018c21STomi Valkeinen 
bt455_write_ovly_next(struct bt455_regs * regs,u8 grey)625832706eSMaciej W. Rozycki static inline void bt455_write_ovly_next(struct bt455_regs *regs, u8 grey)
63f7018c21STomi Valkeinen {
64f7018c21STomi Valkeinen 	wmb();
6501ac59c3SMaciej W. Rozycki 	regs->addr_ovly = 0x0;
66f7018c21STomi Valkeinen 	wmb();
6701ac59c3SMaciej W. Rozycki 	regs->addr_ovly = grey & 0xf;
68f7018c21STomi Valkeinen 	wmb();
6901ac59c3SMaciej W. Rozycki 	regs->addr_ovly = 0x0;
70f7018c21STomi Valkeinen }
715832706eSMaciej W. Rozycki 
bt455_read_cmap_entry(struct bt455_regs * regs,int cr,u8 * grey)725832706eSMaciej W. Rozycki static inline void bt455_read_cmap_entry(struct bt455_regs *regs,
735832706eSMaciej W. Rozycki 					 int cr, u8 *grey)
745832706eSMaciej W. Rozycki {
755832706eSMaciej W. Rozycki 	bt455_select_reg(regs, cr);
765832706eSMaciej W. Rozycki 	bt455_read_cmap_next(regs, grey);
775832706eSMaciej W. Rozycki }
785832706eSMaciej W. Rozycki 
bt455_write_cmap_entry(struct bt455_regs * regs,int cr,u8 grey)795832706eSMaciej W. Rozycki static inline void bt455_write_cmap_entry(struct bt455_regs *regs,
805832706eSMaciej W. Rozycki 					  int cr, u8 grey)
815832706eSMaciej W. Rozycki {
825832706eSMaciej W. Rozycki 	bt455_select_reg(regs, cr);
835832706eSMaciej W. Rozycki 	bt455_write_cmap_next(regs, grey);
845832706eSMaciej W. Rozycki }
855832706eSMaciej W. Rozycki 
bt455_write_ovly_entry(struct bt455_regs * regs,u8 grey)865832706eSMaciej W. Rozycki static inline void bt455_write_ovly_entry(struct bt455_regs *regs, u8 grey)
875832706eSMaciej W. Rozycki {
885832706eSMaciej W. Rozycki 	bt455_reset_reg(regs);
895832706eSMaciej W. Rozycki 	bt455_write_ovly_next(regs, grey);
905832706eSMaciej W. Rozycki }
91