1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/*!
* @file mc9sdz60.c
* @brief Driver for MC9sdz60
*
* @ingroup pmic
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/proc_fs.h>
#include <linux/i2c.h>
#include <asm/arch/clock.h>
#include <asm/uaccess.h>
#include "mc9sdz60.h"
/* I2C bus id and device address of mcu */
#define I2C1_BUS 0
#define MC9SDZ60_I2C_ADDR 0xD2 /* 7bits I2C address */
static struct i2c_client *mc9sdz60_i2c_client;
#define DEBUG_MC9SDZ60 1
#if DEBUG_MC9SDZ60
#define DPRINTK(format, args...) printk(KERN_ERR "mc9sdz60: "format"\n", ##args)
#else
#define DPRINTK(format, args...)
#endif
int mc9sdz60_read_reg(u8 reg, u8 *value)
{
*value = (u8) i2c_smbus_read_byte_data(mc9sdz60_i2c_client, reg);
return 0;
}
int mc9sdz60_write_reg(u8 reg, u8 value)
{
if (i2c_smbus_write_byte_data(mc9sdz60_i2c_client, reg, value) < 0) {
printk(KERN_ERR "%s:write reg errorr:reg=%x,val=%x\n",
__func__, reg, value);
return -1;
}
return 0;
}
/*!
* mc9sdz60 I2C attach function
*
* @param adapter struct i2c_adapter *
* @return 0
*/
static int mc9sdz60_probe(struct i2c_client *client)
{
mc9sdz60_i2c_client = client;
DPRINTK("mc9sdz60_i2c_client = %p", mc9sdz60_i2c_client);
return 0;
}
/*!
* mc9sdz60 I2C detach function
*
* @param client struct i2c_client *
* @return 0
*/
static int mc9sdz60_remove(struct i2c_client *client)
{
return 0;
}
static struct i2c_driver mc9sdz60_i2c_driver = {
.driver = {.owner = THIS_MODULE,
.name = "mc9sdz60",
},
.probe = mc9sdz60_probe,
.remove = mc9sdz60_remove,
};
#define SET_BIT_IN_BYTE(byte, pos) (byte |= (0x01 << pos))
#define CLEAR_BIT_IN_BYTE(byte, pos) (byte &= ~(0x01 << pos))
int mc9sdz60_init(void)
{
int err;
DPRINTK("Freescale mc9sdz60 driver,\
(c) 2008 Freescale Semiconductor, Inc.\n");
err = i2c_add_driver(&mc9sdz60_i2c_driver);
if (err) {
printk(KERN_ERR "mc9sdz60: driver registration failed\n");
return err;
}
DPRINTK("mc9sdz60 inited\n");
return 0;
}
void mc9sdz60_exit(void)
{
i2c_del_driver(&mc9sdz60_i2c_driver);
}
|