2 * Custom GPIO-based PWM driver
4 * Based on w1-gpio-custom by Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
5 * Copyright (C) 2010 Claudio Mignanti <c.mignanti@gmail.com >
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * ---------------------------------------------------------------------------
13 * The behaviour of this driver can be altered by setting some parameters
14 * from the insmod command line.
16 * The following parameters are adjustable:
18 * bus0 These four arguments must be arrays
21 * bus10 <id>,<pin>,<od>
25 * <id> ID to used as device_id for the corresponding bus (required)
26 * <pin> GPIO pin ID for PWM channel (required)
28 * If this driver is built into the kernel, you can use the following kernel
29 * command line parameters, with the same values as the corresponding module
30 * parameters listed above:
32 * pwm-gpio-custom.bus0
33 * pwm-gpio-custom.bus1
34 * pwm-gpio-custom.bunN
35 * pwm-gpio-custom.bus10
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/platform_device.h>
43 #include <linux/pwm/pwm.h>
45 #define DRV_NAME "pwm-gpio-custom"
46 #define DRV_DESC "Custom GPIO-based pwm driver"
47 #define DRV_VERSION "0.1.0"
49 #define PFX DRV_NAME ": "
51 #define BUS_PARAM_ID 0
52 #define BUS_PARAM_PIN 1
54 #define BUS_PARAM_REQUIRED 2
55 #define BUS_PARAM_COUNT 2
56 #define BUS_COUNT_MAX 10
58 static unsigned int bus0
[BUS_PARAM_COUNT
] __initdata
;
59 static unsigned int bus1
[BUS_PARAM_COUNT
] __initdata
;
60 static unsigned int bus2
[BUS_PARAM_COUNT
] __initdata
;
61 static unsigned int bus3
[BUS_PARAM_COUNT
] __initdata
;
62 static unsigned int bus4
[BUS_PARAM_COUNT
] __initdata
;
63 static unsigned int bus5
[BUS_PARAM_COUNT
] __initdata
;
64 static unsigned int bus6
[BUS_PARAM_COUNT
] __initdata
;
65 static unsigned int bus7
[BUS_PARAM_COUNT
] __initdata
;
66 static unsigned int bus8
[BUS_PARAM_COUNT
] __initdata
;
67 static unsigned int bus9
[BUS_PARAM_COUNT
] __initdata
;
69 static unsigned int bus_nump
[BUS_COUNT_MAX
] __initdata
;
71 #define BUS_PARM_DESC " config -> id,pin"
73 module_param_array(bus0
, uint
, &bus_nump
[0], 0);
74 MODULE_PARM_DESC(bus0
, "bus0" BUS_PARM_DESC
);
75 module_param_array(bus1
, uint
, &bus_nump
[1], 0);
76 MODULE_PARM_DESC(bus1
, "bus1" BUS_PARM_DESC
);
77 module_param_array(bus2
, uint
, &bus_nump
[2], 0);
78 MODULE_PARM_DESC(bus2
, "bus2" BUS_PARM_DESC
);
79 module_param_array(bus3
, uint
, &bus_nump
[3], 0);
80 MODULE_PARM_DESC(bus3
, "bus3" BUS_PARM_DESC
);
81 module_param_array(bus4
, uint
, &bus_nump
[4], 0);
82 MODULE_PARM_DESC(bus4
, "bus4" BUS_PARM_DESC
);
83 module_param_array(bus5
, uint
, &bus_nump
[5], 0);
84 MODULE_PARM_DESC(bus5
, "bus5" BUS_PARM_DESC
);
85 module_param_array(bus6
, uint
, &bus_nump
[6], 0);
86 MODULE_PARM_DESC(bus6
, "bus6" BUS_PARM_DESC
);
87 module_param_array(bus7
, uint
, &bus_nump
[7], 0);
88 MODULE_PARM_DESC(bus7
, "bus7" BUS_PARM_DESC
);
89 module_param_array(bus8
, uint
, &bus_nump
[8], 0);
90 MODULE_PARM_DESC(bus8
, "bus8" BUS_PARM_DESC
);
91 module_param_array(bus9
, uint
, &bus_nump
[9], 0);
92 MODULE_PARM_DESC(bus9
, "bus9" BUS_PARM_DESC
);
94 static struct platform_device
*devices
[BUS_COUNT_MAX
];
95 static unsigned int nr_devices
;
97 static void pwm_gpio_custom_cleanup(void)
101 for (i
= 0; i
< nr_devices
; i
++)
103 platform_device_put(devices
[i
]);
106 static int __init
pwm_gpio_custom_add_one(unsigned int id
, unsigned int *params
)
108 struct platform_device
*pdev
;
109 struct gpio_pwm_platform_data pdata
;
115 if (bus_nump
[id
] < BUS_PARAM_REQUIRED
) {
116 printk(KERN_ERR PFX
"not enough parameters for bus%d\n", id
);
121 pdev
= platform_device_alloc("gpio_pwm", params
[BUS_PARAM_ID
]);
127 pdata
.gpio
= params
[BUS_PARAM_PIN
];
129 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
133 err
= platform_device_add(pdev
);
137 devices
[nr_devices
++] = pdev
;
141 platform_device_put(pdev
);
146 static int __init
pwm_gpio_custom_probe(void)
151 printk(KERN_INFO DRV_DESC
" version " DRV_VERSION
"\n");
153 err
= pwm_gpio_custom_add_one(0, bus0
);
156 err
= pwm_gpio_custom_add_one(1, bus1
);
159 err
= pwm_gpio_custom_add_one(2, bus2
);
162 err
= pwm_gpio_custom_add_one(3, bus3
);
165 err
= pwm_gpio_custom_add_one(4, bus4
);
168 err
= pwm_gpio_custom_add_one(5, bus5
);
171 err
= pwm_gpio_custom_add_one(6, bus6
);
174 err
= pwm_gpio_custom_add_one(7, bus7
);
177 err
= pwm_gpio_custom_add_one(8, bus8
);
180 err
= pwm_gpio_custom_add_one(9, bus9
);
184 printk(KERN_ERR PFX
"no bus parameter(s) specified\n");
192 pwm_gpio_custom_cleanup();
197 static int __init
pwm_gpio_custom_init(void)
199 return pwm_gpio_custom_probe();
201 module_init(pwm_gpio_custom_init
);
203 static void __exit
pwm_gpio_custom_exit(void)
205 pwm_gpio_custom_cleanup();
207 module_exit(pwm_gpio_custom_exit
);
209 subsys_initcall(pwm_gpio_custom_probe
);
212 MODULE_LICENSE("GPL v2");
213 MODULE_AUTHOR("Bifferos <bifferos at yahoo.co.uk >");
214 MODULE_AUTHOR("Claudio Mignanti <c.mignanti@gmail.com >");
215 MODULE_DESCRIPTION(DRV_DESC
);
216 MODULE_VERSION(DRV_VERSION
);